从当前缩放谷歌地图获取边界经度和纬度 [英] get boundaries longitude and latitude from current zoom google maps
问题描述
我需要知道当前区域
的四个角的长和宽,就像这张图中的一样
我试过这个,但没有运气:
map.getBounds();
任何帮助?
你在那里的一半。您只需获取地图边界,然后提取(并正确使用)拐角的坐标。
var bounds = map.getBounds();
var ne = bounds.getNorthEast(); //东北角的LatLng
var sw = bounds.getSouthWest(); //西南角的经纬度
您从西南角和西南角以上两项:
var nw = new google.maps.LatLng(ne.lat(), sw.lng());
var se = new google.maps.LatLng(sw.lat(),ne.lng());
请记住,地图必须已经初始化,否则地图边界为空或未定义。
如果您希望更新每个视口的更改,请使用 idle
事件侦听器:
google.maps.event.addListener(map,'idle',function(ev){
//在这里更新坐标
});
i need to know long and lat of my four corners of current area as in this image
i have tried this but with no luck :
map.getBounds();
any help ?
You are half way there. All you need to do is to get the map bounds and then extract (and properly use) the coordinates of the corners.
var bounds = map.getBounds();
var ne = bounds.getNorthEast(); // LatLng of the north-east corner
var sw = bounds.getSouthWest(); // LatLng of the south-west corder
You get north-west and south-east corners from the two above:
var nw = new google.maps.LatLng(ne.lat(), sw.lng());
var se = new google.maps.LatLng(sw.lat(), ne.lng());
Just keep in mind that the map has to be already initialized, otherwise the map bounds are null or undefined.
If you want to be updated about every change of the viewport, use idle
event listener:
google.maps.event.addListener(map, 'idle', function(ev){
// update the coordinates here
});
这篇关于从当前缩放谷歌地图获取边界经度和纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!