我需要帮助获取信息窗口以显示来自位置 [i] [0] 的值
位置 [i] [1] 对于地址值工作得很好,但我希望能够从 var“位置”为信息窗口中的每个标记设置自定义标题。
我可以定义一个 var 来设置内容和信息窗口以这种方式工作,但它对于每个标记都是相同的,而不是从 var“位置”中提取
任何帮助表示赞赏!
function initialize() {
geocoder = new google.maps.Geocoder();
var myOptions = {
zoom: 10,
center: new google.maps.LatLng(0, 0),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(
document.getElementById("map_canvas"),
myOptions);
setMarkers(map, locations);
}
var locations = [
['Bondi Beach', '798 9th Ave, New York, NY', 4],
['Coogee Beach', '42 E 29th St, New York, NY', 5],
['Cronulla Beach', '56 W 25th St, New York, NY', 3],
];
function setMarkers(map, locations) {
var infowindow = new google.maps.InfoWindow();
var bounds = new google.maps.LatLngBounds();
var marker, i;
for (var i=0; i<=locations.length; i++) {
geocoder.geocode({'address': locations[i][1]}, function(results, status) {
marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map,
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.open(map, marker);
infowindow.setContent(locations[i][0]);
}
})(marker, i));
bounds.extend(marker.getPosition());
map.fitBounds(bounds);
})
}
}