0

我想将包含 2000 多个地标的 kml 文件导入到 googla 地图中。我使用谷歌 api v3。我只能显示 200 个地标。我知道我可以使用更多层,但我只想要一个,因为我必须每周刷新它,而且我不想每次都拆分。

感谢您的重播

这是代码:

<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> 
4

2 回答 2

0

如果您的 KML 不是很复杂,您可以尝试使用第三方 KML 解析器(geoxml3geoxml-v3)进行渲染,看看是否可行(或指出您在使用 KmlLayer 时遇到的问题)

于 2013-03-29T03:47:10.813 回答
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 = [

此处的数据如下:

{"title" :"City ZIP CODE STREET" , "lat" :47.2876 , "lng" :20.4978 ,"description" :"YOUR DESCRIPTION"},

                ]

    // 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);

    }
} })();
于 2013-04-08T07:50:12.167 回答