gpt4 book ai didi

php - google.maps.InfoWindow

转载 作者:行者123 更新时间:2023-12-02 18:56:57 26 4
gpt4 key购买 nike

我从 mysql 数据库获取坐标,如下所示

(<?php echo $_Mylat?>, <?php echo $_Mylon?>)
(<?php echo $_Mylat2?>, <?php echo $_Mylon2?>)

当我绘制 map 时,它会显示两个点和方向,如下面的代码所示

    function initialize() {
var mapOptions = {
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: center
};

map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);

for (var i=0; i<a.length;i++)
{
marker = new google.maps.Marker({
map:map,
draggable:true,
animation: google.maps.Animation.DROP,
position: a[i]
});

}
var flightPlanCoordinates = [
new google.maps.LatLng(<?php echo $_Mylat?>, <?php echo $_Mylon?>),
new google.maps.LatLng(<?php echo $_Mylat2?>, <?php echo $_Mylon2?>)
];

例如,当我单击或悬停在标记上时,我希望出现一个消息框,但它不起作用,有人可以帮助我更正代码

     var contentstring = 'hey,this is my location'
var infowindow = new google.maps.InfoWindow ({
content:contentstring
})

google.maps.event.addListener(??????,'click',function(){
infowindow.open(map,????????);});

最佳答案

您必须为每个标记添加一个监听器和信息窗口(在循环内),因此它应该是这样的(未测试):

for (var i=0; i<a.length;i++) {

var marker = new google.maps.Marker({
map:map,
draggable:true,
animation: google.maps.Animation.DROP,
position: a[i]
});

var contentstring = 'hey,this is my location'

var infowindow = new google.maps.InfoWindow({
content: contentString
});

google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});

}

如果您一次只想有一个信息窗口,您应该重复使用信息窗口,如here所述。 .

关于php - google.maps.InfoWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15248550/

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