javascript 设置动画谷歌地图标记
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5356930/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
set animation google maps marker
提问by Gustavo
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
好吧,我试图将 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>
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;
回答by Pierre Valade
try:
尝试:
marker.setAnimation(google.maps.Animation.BOUNCE)
回答by Paul Okeke
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)
to的动画以查看它是否反弹。
Also please check for equality this way in your if
statement
也请在您的if
陈述中以这种方式检查平等
if(bounce==="set"){ /*animate marker*/}
回答by user851716
The setAnimation param should be a string of either "BOUNCE" or "DROP".
setAnimation 参数应该是“BOUNCE”或“DROP”的字符串。
marker.setAnimation("BOUNCE");
标记.setAnimation("BOUNCE");
or
或者
marker.setAnimation("DROP");
标记.setAnimation("DROP");
where marker is a google maps marker object:
其中标记是谷歌地图标记对象: