[英]infowindow opens at same marker!
ok well , i have this code which is called for every position i fetch from a DB, the thing is that whenever i click on a marker the infowindow is shown with the respective marker information , but the position of the infowindow is always avobe the last marker added , in a nut shell info is fine but its not showed where it should be. 好的,我有从数据库中获取的每个位置都需要调用的代码,事实是,每当我单击标记时,都会显示带有相应标记信息的信息窗口,但信息窗口的位置始终是最后一个在螺母壳中添加了标记,信息很好,但未显示应在的位置。
these two are declared when the map its initialized and are global. 这两个是在地图初始化时声明的,并且是全局的。
var infowindow = new google.maps.InfoWindow();
var geocoder=new google.maps.Geocoder
this is the script 这是脚本
function addRoleMarker(lat,lng,rumbo,codigo,velocidad,nE,referer,utc,fecha)
{
var myLatLng = new google.maps.LatLng(lat, lng);
var title='No.'+nE+' '+utc;
baseMarker = new google.maps.Marker({
position: myLatLng,
map: map,
title: title,
zIndex: 1
});
google.maps.event.addListener(baseMarker,'click',function(){
geocoder.geocode({'latLng': myLatLng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
switch(rumbo)
{
case 0:
rumbo='N';
break;
case 1:
rumbo='NE';
break;
case 2:
rumbo='E';
break;
case 3:
rumbo='SE';
break;
case 4:
rumbo='S';
break;
case 5:
rumbo='SO';
break;
case 6:
rumbo='O';
break;
case 7:
rumbo='NO';
break;
}
var tablaR="<table><tr><td>Fecha:</td></tr><td>"+fecha;
tablaR+="</td><tr><td>Fecha UTC:</td></tr><td>"+utc;
tablaR+="</td><tr><td>Velocidad:</td></tr><td>"+velocidad;
tablaR+="</td><tr><td>Rumbo:</td></tr><td>"+rumbo;
tablaR+="</td><tr><td>Direccion:</td></tr><td>"+results[0].formatted_address;
infowindow.setContent(tablaR);
infowindow.open(map,baseMarker);
}else{
alert("No results found");
}
}else{
alert("Geocoder failed due to: " + status);
}});});
}
the number of markers depends on the data fetched acording to a sql query this is the php script 标记的数量取决于根据sql查询获取的数据,这是php脚本
<?
$script="<script type='text/javascript'>";
for($i=0;$i<count($losDatos);$i++)
{
$script.="addRoleMarker(".$losDatos[$i]['latitud'].",".$losDatos[$i]['longitud'].",".$losDatos[$i]['rumbo'].",".$losDatos[$i]['codigo'].",".$losDatos[$i]['velocidad'].",".$losDatos[$i]['numeroEconomico'].",1,'".$losDatos[$i]['utcDate']."','".$losDatos[$i]['localDate']."');";
}
$script.='</script>';
echo $script;
?>
I need to see whole code to make suggestions but it seems you only add listener to one "baseMarker". 我需要查看整个代码来提出建议,但似乎您只将侦听器添加到一个“ baseMarker”中。 So your infoWindow.open(map, baseMarker) opens at the same marker.
因此,您的infoWindow.open(map,baseMarker)将在同一标记处打开。 I think you need to add listener to every marker you create.
我认为您需要将侦听器添加到您创建的每个标记中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.