2013-03-28 59 views
0

我想將包含超過2000個地標的kml文件導入googla地圖。 我使用google api v3。 我只能顯示200個地標。 我知道我可以使用更多圖層,但是我只需要一個圖層,因爲我必須每週刷新一次圖層,而且我不想每次都分割圖層。KML文件超過2000個地標

感謝您的重播

這是代碼:

<script> 

    var map; 
    function initialize() { 

    var mapOptions = { 
     zoom: 8, 
     center: new google.maps.LatLng(47.25,19.5), 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 

    map = new google.maps.Map(document.getElementById('map-canvas'), 
     mapOptions); 

    loadKmlLayer(map); 

    } 

    function loadKmlLayer(map) { 
     var ctaLayer2 = new google.maps.KmlLayer('https://.../asdf.kml', { 
     suppressInfoWindows: false, 
     preserveViewport: false, 
     map: map 
    }); 
} 

    google.maps.event.addDomListener(window, 'load', initialize); 
</script> 
+0

您是否有展示您可以提供的問題的示例KML文件? – geocodezip

+0

您是否在使用[Google Maps API v3 KmlLayer](https://developers.google.com/maps/documentation/javascript/layers#KMLLayers)?或Google MyPlaces(又名「我的地圖」)? ([MyMaps](https://sites.google.com/site/gmapstips/alternative-to-paging-on-my-maps)將KML分成200個「功能」頁面) – geocodezip

回答

0

(函數(){

window.onload = function() { 

    // Creating a new map 
    var map = new google.maps.Map(document.getElementById("map"), { 
     center: new google.maps.LatLng(47.10,19.5), 
     zoom: 8, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }); 

    // Creating the JSON data 
    var json = [ 

DATA喜歡這裏:

{ 「稱號」: 「城郵編STREET」, 「LAT」:47.2876, 「LNG」:20.4978, 「說明」: 「你的描述」},

   ] 

    // Creating a global infoWindow object that will be reused by all markers 
    var infoWindow = new google.maps.InfoWindow(); 

    // Looping through the JSON data 
    for (var i = 0, length = json.length; i < length; i++) 
    { 
     var data = json[i], 
      latLng = new google.maps.LatLng(data.lat, data.lng); 

     // Creating a marker and putting it on the map 
     var marker = new google.maps.Marker({ 
      position: latLng, 
      map: map, 
      title: data.title, 
     // icon: iconimage 

     }); 

     // Creating a closure to retain the correct data, notice how I pass the current data in the loop into the closure (marker, data) 
     (function(marker, data) { 

      // Attaching a click event to the current marker 
      google.maps.event.addListener(marker, "click", function(e) { 
       infoWindow.setContent(data.description); 
       infoWindow.open(map, marker); 
      }); 


     }) 

     //OnClick event 
     (marker, data); 

    } 
} })(); 
0

如果您的KML是不是很複雜,你可以嘗試使用第三方使其KML解析器(geoxml3geoxml-v3) ,看看是否能工程(或指向您正在使用KmlLayer遇到的問題)