[英]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? 我试图将BOUNCE动画设置为特定标记,但是每当我调用
marker.setAnimation(google.maps.Animation.BOUNCE)
方法控制台时,都会说“无法读取未定义的属性'BOUNCE'”,这意味着标记未正确定义? but if I use marker.setTitle('Bouncing') the title does change. 但是如果我使用marker.setTitle('Bouncing'),标题确实会改变。 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
});
if(bounce=='set'){marker.setAnimation(google.maps.Animation.BOUNCE);
marker.setTitle('Bouncing');};
}
</script>
php script 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;
尝试:
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. 或尝试设置没有
if(condition)
的动画来查看动画是否反弹。
Also please check for equality this way in your if
statement 另外请在您的
if
语句中以这种方式检查是否相等
if(bounce==="set"){ /*animate marker*/}
The setAnimation param should be a string of either "BOUNCE" or "DROP". setAnimation参数应为“ BOUNCE”或“ DROP”的字符串。
marker.setAnimation("BOUNCE"); marker.setAnimation(“ BOUNCE”);
or 要么
marker.setAnimation("DROP"); marker.setAnimation(“ DROP”);
where marker is a google maps marker object: 其中marker是google maps标记对象:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.