【发布时间】:2014-07-02 07:39:27
【问题描述】:
提前道歉,因为这可能看起来有点复杂。
我有一个谷歌地图标记数组,我的标记被添加到称为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);
});
};
【问题讨论】:
-
您添加这些属性的部分在哪里?您将每个标记添加到数组的部分在哪里?
-
如何将标记及其详细信息存储到
markersArray? -
我已经添加了如何将标记添加到数组中
-
我没有看到标记添加任何描述,但无论如何...您是否尝试记录
selectedItem.title?你真的有东西在里面吗? -
@AntoJurković 谢谢!我想你已经猜到了!我使用的是
mll而不是查看marker我会给你买一品脱!
标签: javascript google-maps google-maps-api-3 google-maps-markers