如何获取v2 android地图的地图中心? [英] How to get center of map for v2 android maps?
问题描述
在Android版 v1 的Google Maps中,MapView提供了一种便捷的方法:
getMapCenter()
.现在,我无法弄清楚如何使用此api的 v2 来获取地图中心.我已经仔细阅读过API文档,但是没有提及这种功能.请告知.
In Google Maps for Android v1, MapView had a convenience method:
getMapCenter()
. Now I cannot figure out how to get map center with v2 of this api. I have perused the API documentation, but there is no mention of such a feature. Please advise.
谢谢, 伊戈尔(Igor)
Thanks, Igor
推荐答案
我遇到了同样的问题.看来您可以通过这种方式获得中心位置:
I had the same problem. It seems you can get the center this way:
mMap.getCameraPosition().target
其中,mMap是您的活动中的GoogleMap实例.这将返回一个LatLng对象,该对象基本上代表地图的中心.
where mMap is the GoogleMap instance from your activity. This will return a LatLng object which basically represents the center of the map.
请注意,GeoPoint
类不再可用.
Note that the GeoPoint
class is not available anymore.
根据 http://developer.android.com/reference/com/google/android/gms/maps/model/CameraPosition.html
目标是相机指向的位置". (我用示例代码对其进行了测试,对我来说还可以)
target is "The location that the camera is pointing at." (I tested it with the sample code and it worked okay for me)
这篇关于如何获取v2 android地图的地图中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!