我有下面的代碼工作正常:谷歌地圖API V3 - 添加多個事件在一張地圖
google.maps.event.addListener(map, 'dragend', function() {
bounds = map.getBounds();
var ne = bounds.getNorthEast(); // LatLng of the north-east corner
var sw = bounds.getSouthWest(); // LatLng of the south-west corder
$.when(removeMarkers()).then(setMarkers(city, state, ne, sw));
});
當任發生兩個事件之一,該代碼跑到我要的是。我想要的兩個事件是'dragend'和'zoom_changed'。我嘗試了'閒置'事件,它減慢了地圖,並且發生了我不喜歡的事情。這隻會導致糟糕的用戶體驗。然而,'dragend'和'zoom_changed'事件都能很好地工作,我只是沒有找到合併它們的方法。基本上我希望代碼隨時隨地運行,或者放大或縮小。
我曾嘗試這個代碼,我得到那個說「邊界爲空」和它指向的「邊界」的「部分zoom_changed」事件線下方右側的第二個實例的錯誤:
google.maps.event.addListener(map, 'dragend', function() {
bounds = map.getBounds();
var ne = bounds.getNorthEast(); // LatLng of the north-east corner
var sw = bounds.getSouthWest(); // LatLng of the south-west corder
$.when(removeMarkers()).then(setMarkers(city, state, ne, sw));
});
google.maps.event.addListener(map, 'zoom_changed', function() {
bounds = map.getBounds();
var ne = bounds.getNorthEast(); // LatLng of the north-east corner
var sw = bounds.getSouthWest(); // LatLng of the south-west corder
$.when(removeMarkers()).then(setMarkers(city, state, ne, sw));
});
我沒有得到與發佈的代碼錯誤([小提琴](http://jsfiddle.net/geocodezip/kv0ewnj3/1/))。請提供證明問題的[mcve]。 – geocodezip