[英]Google Maps API KMZ file displaying wrong data on click event
我有一个KMZ文件,可以通过使用javascript的链接加载到我的Google Maps应用程序中。 该文件可在Google Earth中完美运行。 问题出在我的应用程序中,当我单击多个元素(区域)之一时:返回的描述数据始终仅来自其中一个元素,而不显示实际单击的正确元素。 这是我尝试过的:
通过将标记放在点击位置来检查地图中的点击事件是否正确。
使用Google地球将数据转换为KML,将其公开放置在我的Google驱动器中,并在我的应用程序中使用来自Google驱动器的直接下载链接。 它显示了数据,但错误继续。
仅使用该层创建了最基本/最空白的应用程序,以确保其他应用程序中的任何其他内容都在干扰。 也没有用。
该文件位于以下网站中: https ://www.voanaboa.pt/codigo-drone,名为“ Regulamento RPA_ver_5.0.kmz”
这是唯一使用kmz文件创建基本应用程序的文件,出于隐私目的,我删除了我的API密钥。
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
var kmlLayer = new google.maps.KmlLayer();
var src = 'https://www.voanaboa.pt/Files/downloads/Regulamento-RPA-ver-5.0.kmz';
var kmlLayer = new google.maps.KmlLayer(src, {
//suppressInfoWindows: true,
preserveViewport: false,
map: map
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=MY_API_KEY&libraries=geometry&callback=initMap"
async defer></script>
您的大多数(但不是全部)地标具有相同的ID“ ID_00000”)。 如果我将其更改为唯一,则多边形的描述将变为唯一:
每KML参考 ,并不必须是唯一的(这是一个“ 斯塔纳德XML ID ”,但我猜测渲染代码是假设它是。
带有更新的kmz文件的代码段:
/* Always set the map height explicitly to define the size of the div * element that contains the map. */ #map { height: 100%; } /* Optional: Makes the sample page fill the window. */ html, body { height: 100%; margin: 0; padding: 0; }
<div id="map"></div> <script> var map; function initMap() { map = new google.maps.Map(document.getElementById('map'), { center: { lat: -34.397, lng: 150.644 }, zoom: 8 }); var kmlLayer = new google.maps.KmlLayer(); var src = 'http://www.geocodezip.com/geoxml3_test/kmz/Regulamento-RPA-ver-5.0a.kmz'; var kmlLayer = new google.maps.KmlLayer(src, { //suppressInfoWindows: true, preserveViewport: false, map: map }); } </script> <script src="https://maps.googleapis.com/maps/api/js?libraries=geometry&callback=initMap" async defer></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.