1
我想通过使用forEach遍历GeoJSON map.data。我想返回每个要素的位置(LatLng),以便根据要素属性将其添加到我的标记数组中。这里是我的尝试:Google forEach map.data功能 - 返回功能LatLng
allMarkers = [];
jQuery.getJSON('json.php', function(data){
points = map.data.addGeoJson(data);
});
var eid = 30;
map.data.forEach(function(feature){
if(feature.getProperty('eid') === eid){
LatLng = feature.getGeometry().LatLng; //not sure how to get LatLng
id = feature.getProerty('id');
var marker = new google.maps.Marker({
position: LatLng,
map: map,
draggable: true,
id: id,
icon: imageActive,
});
allMarkers[id] = marker;
map.data.remove(feature);
}
});
我想创造我想要的那些标记,并从map.data删除这些并保留剩余map.data参考。
任何提示/建议总是赞赏。
在文档中描述的[get()](https://developers.google.com/maps/documentation/javascript/3.exp/reference#Data.Geometry)函数不适合您吗? – geocodezip
请提供一个演示get()的行为的小提琴。 – geocodezip