Google 地图 API 在信息窗口中显示标记位置
Google map API displaying marker location in an infowindow
我有一个 javascript 位置数组 (jarray),我正在遍历它并将每个位置的标记添加到 google 地图上。除了这些标记之外,我还想添加一个显示标记位置的信息窗口。下面的代码在每个标记的信息窗口中显示相同的纬度和经度位置。我希望每个标记在其信息窗口中都有自己的地址。我还尝试将信息窗口的内容设置为结果[0].geometry.location、地址和 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 地图 api 标记没有位置 属性 - 你可以使用位置 - 方法是 marker.getPosition()
https://developers.google.com/maps/documentation/javascript/reference?hl=en#Marker
然后您可以通过使用地理编码(如果需要)将该位置用于地址
https://developers.google.com/maps/documentation/geocoding/intro
代替 marker.location,使用 jarray 位置本身。您可以调整此代码以适合您,因为我不知道您的 jarray 的内容。
var infowindow = new google.maps.InfoWindow({
infowindow.setContent(jarray[i]['lat'] +" " + jarray[i]['lat']);
infowindow.open(map, marker);
});
我有一个 javascript 位置数组 (jarray),我正在遍历它并将每个位置的标记添加到 google 地图上。除了这些标记之外,我还想添加一个显示标记位置的信息窗口。下面的代码在每个标记的信息窗口中显示相同的纬度和经度位置。我希望每个标记在其信息窗口中都有自己的地址。我还尝试将信息窗口的内容设置为结果[0].geometry.location、地址和 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 地图 api 标记没有位置 属性 - 你可以使用位置 - 方法是 marker.getPosition()
https://developers.google.com/maps/documentation/javascript/reference?hl=en#Marker
然后您可以通过使用地理编码(如果需要)将该位置用于地址
https://developers.google.com/maps/documentation/geocoding/intro
代替 marker.location,使用 jarray 位置本身。您可以调整此代码以适合您,因为我不知道您的 jarray 的内容。
var infowindow = new google.maps.InfoWindow({
infowindow.setContent(jarray[i]['lat'] +" " + jarray[i]['lat']);
infowindow.open(map, marker);
});