谷歌地图中的 Moveend 触发

Mar*_*nry 3 javascript google-maps google-maps-api-3

一旦访问者移动地图,我就会尝试通过 Json 添加标记。由于某种原因, moveend 没有被捕获和/或 onClickCallback 函数没有被触发。我哪里出错了。

 google.maps.event.addListener(map, "moveend", function() {
  var bounds = this.getBounds();
  onClickCallback(map);

 });


function onClickCallback(map) {

var bounds = map.getBounds();


  // clearOverlays();



    $.getJSON( 'http://skiweather.eu/gmap4/markers/index.php', {
        swLat: bounds.getSouthWest().lat(), swLon: bounds.getSouthWest().lng(), 
        neLat: bounds.getNorthEast().lat(), neLon: bounds.getNorthEast().lng()}, function(data) { 
        $.each( data.markers, function(i, marker) {


        // Define Marker properties
        var image = new google.maps.MarkerImage(marker.smallimg,
        // This marker is 129 pixels wide by 42 pixels tall.
            new google.maps.Size(42, 42),
        // The origin for this image is 0,0.
            new google.maps.Point(0,0),
        // The anchor for this image is the base of the flagpole at 18,42.
            new google.maps.Point(18, 42)
        );


            $('#map').gmap('addMarker', { 'id' : marker.id,
                'position': new google.maps.LatLng(marker.latitude, marker.longitude),
                'icon' : image,             
                'bounds': true 
            }).click(function() {
                $('#map').gmap('openInfoWindow', { 'content': '<h2>' + marker.loc + '</h2><img src="' + marker.smallimg + '" class="my-map-marker" />'
                 }, this);
            });
        });
    });




}   


google.maps.event.addDomListener(window, 'load', initialize); 
Run Code Online (Sandbox Code Playgroud)

sab*_*ero 5

moveend事件在 google.maps V3 中不再可用,请dragend改用。

尝试这个:

google.maps.event.addListener(map, "dragend", function() {
    var bounds = this.getBounds();
    onClickCallback(map);

});
Run Code Online (Sandbox Code Playgroud)