【发布时间】:2011-10-18 03:48:48
【问题描述】:
我需要知道当前区域四个角的经纬度 就像这张图
我试过了,但没有运气:
map.getBounds();
有什么帮助吗?
【问题讨论】:
我需要知道当前区域四个角的经纬度 就像这张图
我试过了,但没有运气:
map.getBounds();
有什么帮助吗?
【问题讨论】:
你已经成功了一半。您需要做的就是获取地图边界,然后提取(并正确使用)角落的坐标。
var bounds = map.getBounds();
var ne = bounds.getNorthEast(); // LatLng of the north-east corner
var sw = bounds.getSouthWest(); // LatLng of the south-west corder
您可以从上面的两个角落获得西北角和东南角:
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){
// update the coordinates here
});
【讨论】:
在Android中,你可以通过这种方式找到角落LatLng(东北,西南), 在地图中,每次相机监听(意味着手势检测)时,它们都会被调用,
private var mapView: GoogleMap? = null
............
mapView?.setOnCameraMoveStartedListener { reasonCode ->
if (reasonCode == GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE) {
val screenView: LatLngBounds = mapView.getProjection().getVisibleRegion().latLngBounds
var northeast=screenView.northeast
var southwest=screenView.southwest
var center=screenView.center
Log.v("northeast LatLng","-:"+northeast)// LatLng of the north-east Screen
Log.v("southwest LatLng","-:"+southwest)// LatLng of the south-west Screen
Log.v("center LatLng","-:"+center)// LatLng of the center Screen
}
}
【讨论】:
**this is mapbox zoom example**
map.on('zoom', (el) => {
map.getBounds();
});
【讨论】: