2012-08-14 38 views
5

tôi bị này được sửa đổi mã ví dụ từ googleGoogle Maps API v3 thả marker và hình ảnh động trả

var stockholm = new google.maps.LatLng(59.32522, 18.07002); 
var parliament = new google.maps.LatLng(59.327383, 18.06747); 
var marker; 
var map; 

function initialize() { 
    var mapOptions = { 
     zoom: 15, 
     mapTypeId: google.maps.MapTypeId.ROADMAP, 
     center: stockholm 
    }; 

    map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); 

    marker = new google.maps.Marker({ 
     map:map, 
     draggable:true, 
     animation: google.maps.Animation.DROP, 
     position: parliament, 
     icon: '/img/marker.png' 
    }); 
    google.maps.event.addListener(marker, 'click', toggleBounce); 


    setTimeout(function() { marker.setAnimation(google.maps.Animation.BOUNCE); }, 2000); 

} 

function toggleBounce() { 

    if (marker.getAnimation() != null) { 
    marker.setAnimation(null); 
    } else { 
    marker.setAnimation(google.maps.Animation.BOUNCE); 
    } 
} 

và tôi tự hỏi, nếu nó có thể thay đổi hình ảnh động đánh dấu từ trình đơn thả để trả lại sau khi dừng thả hình ảnh động?

Tôi đã quản lý để thay đổi nó bằng hàm setTimeout() nhưng nó không hoạt động trơn tru. Bất kỳ trợ giúp sẽ được đánh giá cao.

Trả lời

0

Bạn có thể thử điều này. :

google.maps.event.addListener(marker, "dragend", function(event) { 
      marker.setAnimation(google.maps.Animation.BOUNCE); 
     }); 
+1

Checked và nó không hoạt động. – debianek

6

Hãy thử thay đổi hoạt ảnh đánh dấu trên google.maps.event.addListener(map, 'idle', function()...) - điều này sẽ được gọi sau khi đánh dấu (s) được thêm vào.

document.write('<script src="https://maps.googleapis.com/maps/api/js">\x3C/script>'); 
 

 
window.onload = function() { 
 
    // Create map 
 
    var map = new google.maps.Map(document.getElementById('map_canvas'), { 
 
     zoom: 12, 
 
     center: new google.maps.LatLng(-33.87, 151.24), 
 
     mapTypeControlOptions: { 
 
      mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style'] 
 
     } 
 
    }); 
 

 
    // Create marker 
 
    var marker = new google.maps.Marker({ 
 
     position: new google.maps.LatLng(-33.890542, 151.274856), 
 
     map: map, 
 
     animation: google.maps.Animation.DROP, 
 
     title: 'Bondi Beach' 
 
    }); 
 
    
 
    // On idle, change marker animation to bounce 
 
    google.maps.event.addListener(map, 'idle', function() { 
 
     marker.setAnimation(google.maps.Animation.BOUNCE); 
 
    }); 
 
}
#map_canvas { 
 
    width: 300px; 
 
    height: 300px; 
 
}
<div id="map_canvas"></div>

Các vấn đề liên quan