gpt4 book ai didi

javascript - 谷歌地图 api 3 上的信息窗口帮助

转载 作者:行者123 更新时间:2023-12-03 12:47:05 25 4
gpt4 key购买 nike

与其他人在本网站上遇到的问题类似,它只显示所有标记中最后一个标记的信息窗口信息。似乎无法使用给出的任何解决方案来解决此问题。此外,我的最后一个标记根本不显示信息窗口。

<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>

非常感谢任何帮助!

最佳答案

我还没有测试过这个,但它应该可以工作 - 也请看看: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>

关于javascript - 谷歌地图 api 3 上的信息窗口帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3979486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com