设置动画谷歌地图标记

Gus*_*avo 7 javascript google-maps

好吧我试图将BOUNCE动画设置为一个特定的标记,但每当我调用marker.setAnimation(google.maps.Animation.BOUNCE)方法控制台时说"无法读取未定义的属性'BOUNCE'"这意味着标记未定义正确吗?但如果我使用marker.setTitle('Bouncing'),标题确实会改变.我做错了什么,这是代码

   <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
            });

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

        }
    </script>
Run Code Online (Sandbox Code Playgroud)

PHP脚本

    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;
Run Code Online (Sandbox Code Playgroud)

Pie*_*ade 11

尝试:

marker.setAnimation(google.maps.Animation.BOUNCE)
Run Code Online (Sandbox Code Playgroud)


小智 -5

setAnimation 参数应该是“BOUNCE”或“DROP”的字符串。

标记.setAnimation(“BOUNCE”);

或者

标记.setAnimation("DROP");

其中标记是谷歌地图标记对象: