是否有任何事件可以检查用户是否缩小地图或缩小地图
我们所做的是......我们希望在更改地图时将纬度或经度发送到服务器。例如,当他们结束拖动时,我们会将纬度和经度发送到服务器,以加载位于该纬度和经度范围内的一些商店位置,我们将把针脚放在上面。因此所有可能的事件都是用户拖动地图,放大,缩小和滚动。我们不会使用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);
});
答案 0 :(得分: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
}())