在设计多个谷歌地图标记的情况下,不会出现用于显示每个标记内容的信息窗口(弹出窗口),尽管包含 用于显示每个谷歌地图标记内容的infowindow.setcontent方法。
这是我使用过的代码-----
--- 这里,locarr包含来自数据库的位置 ---
<script type="text/javascript">
var locarr = $("input[id$='hiddenfiled1']").val().split("#@#");
alert(locarr);
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
zoom: 13,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var icon1 = {
url: 'images/MarkerImg.png',
size: new google.maps.Size(90, 105)
};
var icon2 = {
url: 'images/MarkerImg2.png',
size: new google.maps.Size(90, 105)
};
var bounds = new google.maps.LatLngBounds();
var InfoPopUp = [];
for (var i = 0; i < locarr.length; i++) {
InfoPopUp[i] = new google.maps.InfoWindow({
content: locarr[i],
});
geocoder.geocode({ 'address': locarr[i] }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
icon: icon1,
info: InfoPopUp[i]
});
google.maps.event.addListener(marker, 'mouseover', function (myinmarker) {
return function () {
if (locarr[i] != InfoPopUp[i].getContent()) {
**InfoPopUp[myinmarker].setContent(locarr[i]);**
marker.setIcon(icon2);
InfoPopUp[myinmarker].open(map, marker);
}
}
} (myinmarker));
markers.push(marker);
google.maps.event.addListener(marker, 'mouseout', function (myoutmarker, i) {
return function () {
if (locarr[i] = InfoPopUp[i].getContent()) {
InfoPopUp[myoutmarker].close(map, marker);
marker.setIcon(icon1);
}
else {
google.maps.event.trigger(CalMarker, 'mouseover');
}
}
} (myoutmarker, i));
bounds.extend(marker.getPosition());
} //if ends
else {
alert('Geocode was not successful for the reason: ' + status);
}
});
} //for ends
</script>
在有多个标记的情况下,这里使用 setcontent 不起作用......任何帮助将不胜感激......