GOOGLE MAPS API MARKER不是弹出的

时间:2017-04-14 20:55:00

标签: google-maps google-maps-api-3

我花了一个多小时试图修复我的代码。我仍然不知道它为什么不起作用。我希望你能帮助我。

这是一个链接: MyCode

我对这部分有疑问:

google.maps.event.addListner(marker2, 'click', function(){
marker2.setAnimation(google.maps.Animation.BOUNCE);});

google.maps.event.addListner(marker2, 'click', function(){

marker2.setAnimation(google.maps.Animation.STOP);});

1 个答案:

答案 0 :(得分:1)

您的代码中有拼写错误,您拼写错误.addListner

google.maps.event.addListner(marker2, 'click', function(){
    marker2.setAnimation(google.maps.Animation.BOUNCE);});
google.maps.event.addListner(marker2, 'click', function(){
    marker2.setAnimation(google.maps.Animation.STOP);});

应该是:

google.maps.event.addListener(marker2, 'click', function(){
    marker2.setAnimation(google.maps.Animation.BOUNCE);});
google.maps.event.addListener(marker2, 'click', function(){
    marker2.setAnimation(google.maps.Animation.STOP);});

正确的拼写是.addListener

修改

阅读完你的代码并试图找出你想做的事情后,我想我明白了。尝试对您的代码进行以下更改:

var marker2 = new google.maps.Marker({
    position: { lat: 52.2317554, lng: 21.0061516 },
    map: map,
    title: 'PKiN',
    animation: google.maps.Animation.DROP
});

然后删除两个侦听器并添加它:

google.maps.event.addListener(marker2, 'click', function () {
    if (marker2.getAnimation() !== null) {
        marker2.setAnimation(null);
    } else {
        marker2.setAnimation(google.maps.Animation.BOUNCE);
    }            
});

这个标记首先使标记掉落,当点击它时,它会反弹直到你再次点击它。