【发布时间】:2017-03-22 15:36:49
【问题描述】:
我正在尝试将 Google Maps API 与直接在 Google Maps 平台中创建并导出到 .kml 文件的新图层一起使用。使用的指南是 Google Developer 门户网站上的主要指南。
但是,KML 文件似乎无法正确加载。 http://1c.1contact.ch/mandats/map1.html
连接和加载地图的代码如下(改编自https://developers.google.com/maps/documentation/javascript/kmllayer):
<script>
var map;
var src = 'http://1c.1contact.ch/file/2573/GE.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: 'terrain'
});
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>
完成此 .KML 使用的正确方法是什么?
祝你好运,
【问题讨论】:
标签: parsing import maps kml layer