[英]google maps load only markers in the displayed area
我正在使用Google Maps進行網站開發。 我的數據庫中有很多標記。 我想加載當前地圖中顯示的區域中的標記。 並且當縮放更改時,標記的數量也應相應調整。 最好的方法是什么? 提前致謝!
使用界限
aNord = this.map.getBounds().getNorthEast().lat();
aEst = this.map.getBounds().getNorthEast().lng();
aSud = this.map.getBounds().getSouthWest().lat();
aOvest = this.map.getBounds().getSouthWest().lng();
用於從數據庫中篩選(服務器端)數據(在這種情況下為php)
"select lat, lng
from your_table
where lat >= $minLat
AND lat <= $maxLat
AND lng <= $maxLng
AND lng >= $minLng";
當用戶更改縮放級別或平移地圖時,還可以使用bounds_changed函數添加或刪除數據。
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: {lat:41.082774, lng: 28.86821},
disableDefaultUI: true
});
google.maps.event.addListener(map, 'bounds_changed', function() {
aNord = map.getBounds().getNorthEast().lat();
aEst = map.getBounds().getNorthEast().lng();
aSud = map.getBounds().getSouthWest().lat();
aOvest = map.getBounds().getSouthWest().lng();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.