2017-02-10 152 views
1

我正試圖在Google地圖上顯示KML。地圖加載完美,但KML完全不顯示。另外,我在控制檯中沒有收到任何錯誤消息。KML圖層不顯示在地圖上

我從gadm.org下載了一個.kmz文件,解壓縮並提取.kml文件。

這是我的代碼和我的KML的URL。 http://locallocal.com/endline/mex2.kml

<script> 
    var map; 
    var src = 'http://locallocal.com/endline/mex2.kml'; 

    /** 
    * Initializes the map and calls the function that loads the KML layer. 
    */ 
    function initMap() { 
    map = new google.maps.Map(document.getElementById('map'), { 
     center: new google.maps.LatLng(-19.257753, 146.823688), 
     zoom: 2, 
     mapTypeId: 'roadmap' 
    }); 
    loadKmlLayer(src, map); 
    } 

    /** 
    * Adds a KMLLayer based on the URL passed. Clicking on a marker 
    * results in the balloon content being loaded into the right-hand div. 
    * @param {string} src A URL for a KML file. 
    */ 
    function loadKmlLayer(src, map) { 
    var kmlLayer = new google.maps.KmlLayer(src, { 
     suppressInfoWindows: true, 
     preserveViewport: false, 
     map: map 
    }); 
    google.maps.event.addListener(kmlLayer, 'click', function(event) { 
     var content = event.featureData.infoWindowHtml; 
     var testimonial = document.getElementById('capture'); 
     testimonial.innerHTML = content; 
    }); 
    } 
</script> 
<script async defer 
src="https://maps.googleapis.com/maps/api/js?key=[MYKEY]&callback=initMap"> 
+0

相關問題:[與谷歌地圖工作的縣KML數據](http://stackoverflow.com/questions/35347003/county-kml-data-that-works-with-google-maps) – geocodezip

回答

3

我得到KML狀態:INVALID_DOCUMENT(link)與KML。您的KML過大(這是5.8 MB),它並不滿足the documentation這個要求:

  • 獲取最大文件大小(原始KML,原始GeoRSS或壓縮的KMZ)3MB

我可以加載它geoxml3,它沒有這個限制。

或者,我可以壓縮它(使它成爲一個名爲.kmz文件),它的工作原理(這是1.3 MB):

loading it as a KMZ file

+0

謝謝!我正把頭撞在牆上 – user954208

0

如果它不是KML和KML網址內無效的XML將從瀏覽器下載,然後嘗試重命名您的kml文件。重命名是唯一有效的解決方案。而且這不是我的瀏覽器緩存,因爲我清理了很多次。看起來谷歌必須在api的末尾做一些緩存。