0
提前道歉,因爲這可能看起來有點複雜。谷歌地圖API從陣列到標記缺少數據
我有一個谷歌地圖標記陣列,我的標記被添加到被稱爲markersArray
。
每個標記存儲的詳細信息是緯度,經度,標題,說明。
使用下面的代碼,在運行時被點擊我的地圖
google.maps.event.addListener(marker, 'click', function(mll) {
console.log(mll);
console.log(markersArray);
var html= "<div style='color:#000;background-color:#fff;padding:5px;width:150px;'><p></p></div>";
iw = new google.maps.InfoWindow({content:html});
iw.open(map,marker);
});
mll
標記顯示日誌的實際標記和markersArray
只是表明我在陣列內的標記列表。
我注意到存儲在markersArray
中的數據沒有被帶入實際的標記本身。
有沒有辦法做到這一點?
如果沒有辦法使用Javascript從markersArray
中查找title
,具體取決於您將在下圖中看到的latLng
值。
我截圖我得到什麼,當我運行標記點擊功能被添加
標記使用AngularJS如下:
$scope.createmarker = function() {
geocoder.geocode({
'address': selectedItem.gps
}, function (response, status) {
geocode_results = new Array();
geocode_results['status'] = status;
top_location = response[0];
var lat = Math.round(top_location.geometry.location.lat() * 1000000)/1000000;
var lng = Math.round(top_location.geometry.location.lng() * 1000000)/1000000;
geocode_results['lat'] = lat;
geocode_results['lng'] = lng;
geocode_results['l_type'] = top_location.geometry.location_type;
marker = new google.maps.Marker({
icon: mapIcon,
position: new google.maps.LatLng(lat, lng),
map: map,
title: selectedItem.title
});
markersArray.push(marker);
console.log(markersArray);
console.log(marker);
});
};
哪裏是你的一部分dd這些屬性?哪裏是你添加每個標記到陣列的部分? – MrUpsidown
如何將標記及其細節存儲到'markersArray'中? –
我已經添加了如何將標記添加到數組 – ngplayground