Android Google地图获得边界坐标

时间:2013-02-05 05:01:27

标签: android google-maps-android-api-2 bounds

我在我的应用程序中使用Google Maps v2。当用户平移或放大屏幕时,我想获得地图区域,我想在屏幕视图部分中仅获取POI。
我浏览了文档但找不到任何帮助。

2 个答案:

答案 0 :(得分:53)

您需要使用ProjectionVisibleRegion类才能获得可见的LatLng区域。
所以你的代码看起来像是:

LatLngBounds curScreen = googleMap.getProjection()
    .getVisibleRegion().latLngBounds;

答案 1 :(得分:0)

在 Android(Kotlin) 中,您可以通过这种方式找到 LatLng,在每次缩放或。手势检测

private var mMap: GoogleMap? = null
..........



    mMap?.setOnCameraMoveStartedListener { reasonCode ->
        if (reasonCode == GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE) {
            val curScreen: LatLngBounds =  mMap!!.getProjection().getVisibleRegion().latLngBounds
            var northeast=curScreen.northeast
            var southwest=curScreen.southwest
            var center=curScreen.center
            Log.v("northeast LatLng","-:"+northeast)
            Log.v("southwest LatLng","-:"+southwest)
            Log.v("center LatLng","-:"+center)
        }
    }