开发者

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

<?
$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". So your infoWindow.open(map, baseMarker) opens at the same marker. I think you need to add listener to every marker you create.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜