5
我正在使用Google Maps API(v3)呈現世界地圖。當我放大縮小(縮放級別1)並開始拖動畫布時,我可以移出地圖邊界,外側區域以灰色顯示。我想阻止用戶將地圖拖到世界地圖邊界之外。我怎麼做?Google Maps API:防止拖入灰色區域
我正在使用Google Maps API(v3)呈現世界地圖。當我放大縮小(縮放級別1)並開始拖動畫布時,我可以移出地圖邊界,外側區域以灰色顯示。我想阻止用戶將地圖拖到世界地圖邊界之外。我怎麼做?Google Maps API:防止拖入灰色區域
你可以設置minZoom和maxZoom,以確保可用的縮放級別在你的界限內,希望有幫助嗎?
google.maps.event.addListener(Map, 'drag', function(){
var proj =Map.getProjection();
var bounds = Map.getBounds();
var sLat =Map.getBounds().getSouthWest().lat();
var nLat = Map.getBounds().getNorthEast().lat();
if (sLat < -85 || nLat > 85) {
// alert('Gray area visible');
Map.setOptions({
center: new google.maps.LatLng(
cen_Lati , // set Latitude for center of map here
cen_Longi) // set Langitude for center of map here
});
// Map.fitBounds(boundsNew); Or Define bound that u want show
}
});
添加縮放級別不會阻止用戶拖動地圖,使灰色區域可見。 – JensB 2015-09-06 16:20:19
這只是縮放,而不是拖動地圖。 – 2016-10-19 09:12:15