我有一个位置的javascript数组(jarray),我在其中进行了遍历并将每个位置的标记添加到Google地图上。除了这些标记之外,我还想添加一个显示标记位置的信息窗口。下面的代码在每个标记的信息窗口中显示相同的纬度和经度位置。我希望每个标记在其信息窗口中都有其自己的地址。我还尝试将信息窗口的内容设置为results [0] .geometry.location,address和jarray [i]都没有成功。任何想法都将不胜感激。
for(var i = 0; i < jarray.length; i++){
geocoder.geocode({'address': jarray[i]},
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
var marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map,
title: "Marker",
icon: image
});
var infowindow = new google.maps.InfoWindow({
content: "<p>"+marker.position+"</p>"
});
marker.addListener('mouseover', function() {
infowindow.open(map, marker);
});
我不认为Google Maps api标记具有location属性-您可以使用position-方法是marker.getPosition()
https://developers.google.com/maps/documentation/javascript/reference?hl=zh_CN#Marker
然后,您可以通过地理编码使用该位置到地址(如果需要)
https://developers.google.com/maps/documentation/geocoding/intro
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句