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