[英]KML Layer not displaying on Map
我正在嘗試在 Google 地圖上顯示 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">
如果它不是 kml 中的無效 xml,並且 kml url 將從瀏覽器下載,然后嘗試重命名您的 kml 文件。 重命名是唯一有效的解決方案。 這不是我的瀏覽器緩存,因為我清除了很多次。 看來谷歌必須在他們的 api 端進行某種緩存。
我的朋友們,google maps javascript API,KML 層,將 KML 大小限制為 10MB。 超過 10MB,您將在 kmllayer 對象上獲得無效文檔狀態。
您的 KML 必須首先加載到 google KML 服務,然后將平鋪圖像返回給您。 因此,您的 KML 大小必須小於 10MB。
https://developers.google.com/maps/documentation/javascript/kmllayer#restrictions
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.