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 回答