0

ユーザー側がマップをズームインしたか、マップをズームアウトしたかを確認するイベントはありますか

私たちがしていることは..サーバーがマップに変更を加えたときに、緯度または経度をサーバーに送信したいということです。たとえば、ドラッグが終了すると、緯度と経度をサーバーに送信して、その緯度と経度の境界内にあるショップの場所をロードし、ピンを配置します。したがって、考えられるすべてのイベントは、ユーザーがマップをドラッグする、ズームインする、ズームアウトする、スクロールすることです。常にサーバーにデータを送信するので、bounds_changed イベントは使用しません。

    //Get bound of the map when a user dragged the map.
    google.maps.event.addListener(map, 'dragend', function () {
        bound = map.getBounds();
        var latlng_NE = bound.getNorthEast();
        var latlng_SW = bound.getSouthWest();

       // Some code to send latitude or longtitude to server here
       throw new Error(latlng_NE, latlng_SW);
    });
4

1 に答える 1

2

Google Maps API ドキュメントから

google.maps.event.addListener(map, 'zoom_changed', function() {
    setTimeout(moveToDarwin, 3000);
});

https://developers.google.com/maps/documentation/javascript/events ;


編集

// closure
(function() {

    var timeout = null;
    var delay = 500;

    function react() {
        if (timeout) {
            clearTimeout(timeout)
        }
        timeout = setTimeout(react, delay)
    }

    function sendBoundsToServer() {
        bound = map.getBounds();
        var latlng_NE = bound.getNorthEast();
        var latlng_SW = bound.getSouthWest();            
        // some AJAX action to send bound to server
        // ...
    }
    //Action after a user dragged the map.
    google.maps.event.addListener(map, 'zoom_changed', function () {
       // Some code to send latitude or longtitude to server here
       setTimeout(sendMessageToServer, 1000)
    });
    google.maps.event.addListener(map, 'dragend', function () {
       // Some code to send latitude or longtitude to server here
       setTimeout(react, 1000)
    });


    // Add more events here like the two above  


}())
于 2012-07-22T09:47:15.667 に答える