[英]google.maps.InfoWindow
i am getting my cordinates from mysql database as shown below 我从mysql数据库获取我的坐标,如下所示
(<?php echo $_Mylat?>, <?php echo $_Mylon?>)
(<?php echo $_Mylat2?>, <?php echo $_Mylon2?>)
When i plot the map, it shows the two points and the direction as shown in the code below 当我绘制地图时,它会显示两个点和方向,如下面的代码所示
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?>)
];
i want a message box to come up when i click or hover on the markers for example but it doesn't work, can someone help me to correct the code 当我点击或悬停在标记上时,我想要一个消息框,但它不起作用,有人可以帮我纠正代码
var contentstring = 'hey,this is my location'
var infowindow = new google.maps.InfoWindow ({
content:contentstring
})
google.maps.event.addListener(??????,'click',function(){
infowindow.open(map,????????);});
You have to add a listener and infowindow for each marker (inside the loop), so it should be something like this (not tested): 你必须为每个标记(在循环内)添加一个监听器和infowindow,所以它应该像这样(未经测试):
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);
});
}
If you only want to have one InfoWindow at a time you should reuse the info window as described here . 如果您只想一次拥有一个InfoWindow,则应重复使用此处所述的信息窗口。
Generally infowindows go with markers. 一般情况下,infowindows会使用标记。 When setting the marker, also set the info window and click events.
设置标记时,还要设置信息窗口并单击事件。
See the google docs for an example of infowindow usage. 有关infowindow用法的示例,请参阅google文档 。
Not sure where you are getting a.length from but I am assuming thats the two points of your flight plan. 不确定你从哪里获得a.length但是我假设你的飞行计划的两点。
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 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);
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.