本文介绍了Infowindow帮助谷歌地图api 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
与其他人在本网站上遇到的问题类似,只显示所有标记中的最后一个标记的信息窗口信息。似乎无法用任何解决方案解决这个问题。
Having similar problem as others have had on this website where it shows only the last marker's info window info in all markers. Can't seem to solve this with any of the solutions given. Also, the last one of my markers doesn't show an info window at all.
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="data2.json"></script>
<script type="text/javascript" src="js/markerclusterer.js"></script>
<script type="text/javascript">
google.load('maps', '3', {
other_params: 'sensor=false'
});
google.setOnLoadCallback(initialize);
function initialize() {
var center = new google.maps.LatLng(55.4419, -4.1419);
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 5,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var markers = [];
for (var i = 0, dataPhoto; dataPhoto = data.markers[i]; i++) {
var latLng = new google.maps.LatLng(dataPhoto.latitude,dataPhoto.longitude);
var theTitle = dataPhoto.address;
var contentString = '<div align="left"><img src="logo.gif" alt="" width="242" height="71" /><br /><br /><p style="color:#000000;">' + data.markers[i].address + '<br />' + dataPhoto.telephone + '</p></div>';
var infowindow = new google.maps.InfoWindow({
content: contentString,
});
var thisIcon = 'markers/image.png';
for (var i = 0, marker; marker = markers[i]; i++) {google.maps.event.addListener(marker, 'click', function() {infowindow.open(map,this);});
}
var marker = new google.maps.Marker({
position: latLng,
clickable: true,
title: theTitle,
icon: thisIcon,
});
markers.push(marker);
}
var markerCluster = new MarkerClusterer(map, markers);
}
</script>
非常感谢任何帮助!
推荐答案
我还没有测试过这个,但它应该可以工作 - 也请看看:
I have not tested this but it should work - also please have a look at : http://code.google.com/apis/maps/documentation/javascript/events.html#EventClosures
<script src="http://www.google.com/jsapi">
</script>
<script type="text/javascript" src="data2.json">
</script>
<script type="text/javascript" src="js/markerclusterer.js">
</script>
<script type="text/javascript">
google.load('maps', '3', {
other_params: 'sensor=false'
});
google.setOnLoadCallback(initialize);
function initialize(){
var center = new google.maps.LatLng(55.4419, -4.1419);
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 5,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var markers = [];
for (var i = 0, dataPhoto; dataPhoto = data.markers[i]; i++) {
var latLng = new google.maps.LatLng(dataPhoto.latitude, dataPhoto.longitude);
var theTitle = dataPhoto.address;
var contentString = '<div align="left"><img src="logo.gif" alt="" width="242" height="71" /><br /><br /><p style="color:#000000;">' + data.markers[i].address + '<br />' + dataPhoto.telephone + '</p></div>';
var thisIcon = 'markers/image.png';
var marker = new google.maps.Marker({
position: latLng,
clickable: true,
title: theTitle,
icon: thisIcon,
});
attachIWindow(contentString, marker);
markers.push(marker);
}
var markerCluster = new MarkerClusterer(map, markers);
}
function attachIWindow(content, marker){
var infowindow = new google.maps.InfoWindow({
content: content,
});
google.maps.event.addListener(marker, 'click', function(){
infowindow.open(map, marker);
});
}
</script>
这篇关于Infowindow帮助谷歌地图api 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!