开发者

google map v3 KmlLayer, Geocoder

I have some problems making a google map that loads XML file that have addresses instead of latlng. XML file holds about 10 records. I can not figure out how to do this.

    $(document).ready(function(){

    var refreshId = setInterval(function(){

        var latlng = new google.maps.LatLng(18.156291402835436, 22.2802734375);
        var myOptions = {
          zoom: 3,
          center: latlng,
          mapTypeId: google.maps.MapTypeId.TERRAIN
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);

        var georssLayer = new google.maps.KmlLayer("da开发者_Python百科ta.xml");

            var geocoder = new google.maps.Geocoder();
           //????
            georssLayer.setMap(map);

        }, 10000);
  });



<div id="map_canvas" style="width:99%; height:99%"></div>

help plz


OK my solution after 2 days:

load the XML with ajax and loop the document for address, then after

map = new google.maps.Map()

address is the address from xml, should have street, city, country

geocoder.geocode({ 'address': address }, function (results, status) {

    if (status == google.maps.GeocoderStatus.OK) {
       //Make the latitude*longitude format
       var latlng = new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng());
       //Show me the money!!!
       var marker = new google.maps.Marker({
           map: map,
           position: latlng,
           title: address
       });


       google.maps.event.addListener(marker, 'click', function() {
           infowindow.setContent(html);
           infowindow.open(map,marker);
       });
       google.maps.event.trigger(marker, 'click');
   }
   });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜