Javascript 谷歌地图个人标记信息窗口-如何?
我有一个正在工作的multy markers脚本。标记打印在地图上,但当我点击任何标记时,我可以看到相同的信息窗口。。这个循环中出现了一些错误:Javascript 谷歌地图个人标记信息窗口-如何?,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我有一个正在工作的multy markers脚本。标记打印在地图上,但当我点击任何标记时,我可以看到相同的信息窗口。。这个循环中出现了一些错误: function bindInfoWindow(marker, map, infowindow, content) { google.maps.event.addListener(marker, 'click', function() { infowindow.setContent(content); i
function bindInfoWindow(marker, map, infowindow, content) {
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(content);
infowindow.open(map, marker);
});
}
function initialize() {
var map;
var locations = <?php echo json_encode($location); ?>;
var bounds = new google.maps.LatLngBounds();
var mapOptions = {
mapTypeId: 'roadmap'
};
// Display a map on the page
map = new google.maps.Map(document.getElementById("googlemap"), mapOptions);
// Multiple Markers
var markers = locations;
// Display multiple markers on a map
var infoWindow = new google.maps.InfoWindow();
// Loop through our array of markers & place each one on the map
for( i = 0; i < markers.length; i++ ){
loc_array = markers[i].split(",");
var position = new google.maps.LatLng(loc_array[1], loc_array[2]);
bounds.extend(position);
marker = new google.maps.Marker({
position: position,
map: map,
draggable: false,
raiseOnDrag: true,
title: loc_array[0]
});
// Info Window Content
content=loc_array[0] + " - <a class='ac' onclick='move("+ loc_array[4] +");' href='#'>" + <?php echo json_encode($lang['view_profile']);?> + "</a><span class='p'>" + <?php echo json_encode($lang['phone']);?> + ": " + loc_array[6] + " </span><span class='p'>" + <?php echo json_encode($lang['address']);?> + ": " + loc_array[5] + ", " + loc_array[7] + ", " + loc_array[8] + "</span>";
bindInfoWindow(marker, map, infoWindow, content);
//infowindow = new google.maps.InfoWindow();
console.log(content);
// Allow each marker to have an info window
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infoWindow.setContent(content);
infoWindow.open(map, marker);
}
})(marker, i));
// Automatically center the map fitting all markers on the screen
map.fitBounds(bounds);
}
bounds.extend(marker.position);
// Override our map zoom level once our fitBounds function runs (Make sure it only runs once)
var boundsListener = google.maps.event.addListener((map), 'bounds_changed', function(event) {
map.fitBounds(bounds);
google.maps.event.removeListener(boundsListener);
});
}
我在body load上调用initialize()
请帮助我,我错了,谢谢 首先,以以下方式全局声明
infowindow
:
var infoWindow = new google.maps.InfoWindow();
创建标记和内容字符串后,只需调用此函数:
bindInfoWindow(marker, map, infoWindow, content);
这是函数bindInfoWindow()
#sunil,谢谢,我用你的代码更新了代码,但没有变化。请查看我在网站上编辑的完整代码,包括您的更改。。所有标记的弹出信息窗口仍然相同。。请检查我的更新代码,谢谢调用bindInfoWindow()函数后您没有删除代码,…删除此代码//允许每个标记都有一个信息窗口google.maps.event.addListener(标记,'单击',(函数(标记,i){返回函数(){infoWindow.setContent(内容);infoWindow.open(地图,记号笔);}}}(记号笔,我);哦,是的:)现在它正在工作。非常感谢你的帮助!可能重复的
bindInfoWindow(marker, map, infoWindow, content);
function bindInfoWindow(marker, map, infowindow, content) {
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(content);
infowindow.open(map, marker);
});
}