【问题标题】:KML file more than 2000 placemarksKML 文件超过 2000 个地标
【发布时间】:2013-03-28 12:09:21
【问题描述】:

我想将包含 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> 

【问题讨论】:

  • 您是否有展示您可以提供的问题的示例 KML 文件?
  • 您使用的是Google Maps API v3 KmlLayer吗?还是 Google MyPlaces(又名“我的地图”)? (MyMaps 将 KML 分解为 200 个“功能”页面)

标签: google-maps-api-3 kml


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    (函数() {

    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);
    
        }
    } })();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-17
      • 1970-01-01
      • 1970-01-01
      • 2013-06-04
      • 2013-04-14
      • 1970-01-01
      相关资源
      最近更新 更多