简体   繁体   English

在Google Maps HTML中简单添加kml层

[英]simple add kml layer in google maps html

My first question regarding google maps API. 关于Google Maps API的第一个问题。 What this code does is that it directs us to a location on a map. 该代码的作用是将我们定向到地图上的某个位置。 The problem is I'm trying to add google objects like polylines to it but I can't see them on the webpage. 问题是我正在尝试向其中添加折线之类的google对象,但在网页上看不到它们。

1.Why I can't see the polyline drawn? 1.为什么看不到折线?

How to add 1. polylines 2.kml layers 3.xml data from separate file into the button from the code below. 如何添加1.将折线2.kml层3.xml数据从单独的文件添加到以下代码的按钮中。

    <!--
        var mapa;       // obiekt globalny
        var dymek;      // okno z informacjami
        var geokoder    = new google.maps.Geocoder();

        var rozmiar             = new google.maps.Size(32,32);
        var rozmiar_cien        = new google.maps.Size(59,32);
        var punkt_startowy      = new google.maps.Point(0,0);
        var punkt_zaczepienia   = new google.maps.Point(16,16);
        var ikona               = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal3/icon52.png", rozmiar, punkt_startowy, punkt_zaczepienia);
        var cien                = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal3/icon52s.png", rozmiar_cien, punkt_startowy, punkt_zaczepienia);
        var wskaznik            = new google.maps.Marker({icon: ikona, shadow: cien});

        function mapaStart()
        {
            var wspolrzedne = new google.maps.LatLng(37.7671, -122.4206);
            var opcjeMapy = {
                zoom: 15,
                center: wspolrzedne,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                disableDefaultUI: true
            };
            mapa = new google.maps.Map(document.getElementById("mapka"), opcjeMapy);
            dymek = new google.maps.InfoWindow();

            // Creating an array that will contain the points for the polyline 
            var route = [     
                new google.maps.LatLng(37.7671, -122.4206),       
                new google.maps.LatLng(34.0485, -118.2568)    
            ];          // Creating the polyline object 

            var polyline = new google.maps.Polyline({
                path: route, strokeColor: "#ff0000",
                strokeOpacity: 0.6,      
                strokeWeight: 5     });        
            // Adding the polyline to the map 
            polyline.setMap(map);      



            geokoder.geocode({address: 'Szczecin, Krzywoustego 23'}, obslugaGeokodowania);



        }


        function skoczDoAdresu(adres)
        {
            wskaznik.setMap(null);
            geokoder.geocode({address: adres}, function(wyniki, status)
            {
                if(status == google.maps.GeocoderStatus.OK)
                {
                    mapa.setCenter(wyniki[0].geometry.location);
                    wskaznik.setPosition(wyniki[0].geometry.location);
                    wskaznik.setMap(mapa);
                    dymek.open(mapa, wskaznik);
                    dymek.setContent('<strong>Poszukiwany adres</strong><br />'+adres);
                }
                else
                {
                    alert("Nie znalazłem podanego adresu!");
                }
            });
        }

        function obslugaGeokodowania(wyniki, status)
        {

        }

    -->
</script>

You can't see the polyline because "map" is not defined in this line: 您看不到折线,因为此行未定义“地图”:

// Adding the polyline to the map 
polyline.setMap(map);    

Your javascript console should tell you that, the google.maps.Map object is called "mapa" 您的JavaScript控制台应该告诉您,google.maps.Map对象称为“ mapa”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM