开发者

set animation google maps marker

well im trying to set the BOUNCE animation to a specific marker but whenever i call the marker.setAnimation(google.maps.Animation.BOUNCE) method console says "Cannot read property 'BOUNCE' of undefined" this means that marker is not defined right? but if I use marker.setTitle('Bouncing') the title does change. am i doing something wrong , here is the code

   <script type="text/javascript">
        function addMarker(lat,lng,img,title,bounce)
        {
         var myLatLng = new google.maps.LatLng(lat, lng);

        var marker = new google.maps.Marker({
                position: myLatLng,
                map: map,
                icon: img,
            title: title,
            zIndex: 1
            })开发者_Python百科;

            if(bounce=='set'){marker.setAnimation(google.maps.Animation.BOUNCE);
            marker.setTitle('Bouncing');};

        }
    </script>

php script

    for($i=0;$i<count($losDatos);$i++)
    {

    $utc=new DateTime($losDatos[$i]['fechaUtc']);
    $utc->modify('-'.horarioVerano().' hours');
    echo $utc->format("Y-m-d H:i:s");
    if($losDatos[$i]['camion']==$camion)
    {
    $script.="addMarker(".$losDatos[$i]['latitud'].",".$losDatos[$i]['longitud'].",".$losDatos[$i]['img'].",".$losDatos[$i]['nombre'].",'set');";
    }else
    {
       $script.="addMarker(".$losDatos[$i]['latitud'].",".$losDatos[$i]['longitud'].",".$losDatos[$i]['img'].",".$losDatos[$i]['nombre'].");";
    }

    }

echo $script;


try:

marker.setAnimation(google.maps.Animation.BOUNCE)


The way You specified it in you code is correct.

{
  marker.setAnimation(google.maps.Animation.BOUNCE);
}

What you should check is if the marker is really referencing a marker object on the map.

OR

You can try setting the animation through marker options.

var markerOptions = {animation:google.maps.Animation.BOUNCE}

or Try setting the animation without the if(condition) to to see if it bounces.

Also please check for equality this way in your if statement

if(bounce==="set"){ /*animate marker*/}


The setAnimation param should be a string of either "BOUNCE" or "DROP".

marker.setAnimation("BOUNCE");

or

marker.setAnimation("DROP");

where marker is a google maps marker object:

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜