Google maps api 3 从当前的缩放谷歌地图获取边界经度和纬度

Google maps api 3 从当前的缩放谷歌地图获取边界经度和纬度,google-maps-api-3,maps,Google Maps Api 3,Maps,我需要知道当前区域四个角的长度和纬度 如图所示 我尝试过这个,但没有成功: map.getBounds(); 有什么帮助吗?你已经成功了一半。您所需要做的就是获取贴图边界,然后提取(并正确使用)角点的坐标 var-bounds=map.getBounds(); var ne=bounds.getNorthEast();//东北角的板条 var sw=bounds.getSouthWest();//西南部录像机的板条 从上面两个角可以看到西北角和东南角: var nw=new google.

我需要知道当前区域四个角的长度和纬度 如图所示

我尝试过这个,但没有成功:

map.getBounds();

有什么帮助吗?

你已经成功了一半。您所需要做的就是获取贴图边界,然后提取(并正确使用)角点的坐标

var-bounds=map.getBounds();
var ne=bounds.getNorthEast();//东北角的板条
var sw=bounds.getSouthWest();//西南部录像机的板条
从上面两个角可以看到西北角和东南角:

var nw=new google.maps.LatLng(ne.lat(),sw.lng());
var se=new google.maps.LatLng(sw.lat(),ne.lng());
请记住,映射必须已经初始化,否则映射边界为null或未定义

如果要更新视口的每次更改,请使用
idle
事件侦听器:

google.maps.event.addListener(映射,'idle',函数(ev){
//在这里更新坐标
});

在安卓系统中,你可以通过这种方式找到街角(东北、西南), 在地图中,每次摄像头监听(表示手势检测)时,都会调用它们

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
        }
    }

谢谢你帮我省去了用大脑寻找西北角和东南角的麻烦。@Tomic到目前为止我知道iOS SDK的谷歌地图api现在已经付费了,你能给我其他的解决方案吗?
    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
        }
    }