我使用 JS 运行我的谷歌地图,我完美地添加了 kml 层,当我点击线上的某个点时,我需要获取线点击地标的列表,而不仅仅是点击点的经纬度。
这是我试过的:
var kml_layer = new google.maps.KmlLayer(src, {
suppressInfoWindows: true,
preserveViewport: true,
map: map
});
kml_layer.addListener('click', (kmlEvent) => {
var clickedFeature = kmlEvent.featureData;
var geometries = clickedFeature.geometry.getGeometries();
console.log("OOOOOOOO " + geometries);
for (var i = 0; i < geometries.length; i++) {
var geometry = geometries[i];
// Check if the geometry is a LineString
if (geometry.getType() == 'LineString') {
// Get the coordinates of the LineString
var coordinates = geometry.getArray();
// Do something with the coordinates
console.log(coordinates);
}
}
但是我得到这个错误:
"Uncaught TypeError: Cannot read properties of undefined (reading 'getGeometries')"