Java Android GMaps v2-获取地图中心的位置&;地图高度和宽度
我试图在googlemapsv2api中获取地图中心的经纬度&获取地图的宽度和长度 这是我的旧代码(来自我开始修改的GMAPSV1): 如何使用Android GMaps V2 API执行与mapView.getMapCenter()、mapView.getHeight()和mapView.getWidth()相同的功能?获取中心:Java Android GMaps v2-获取地图中心的位置&;地图高度和宽度,java,android,google-maps-android-api-2,google-maps-api-2,android-maps-v2,Java,Android,Google Maps Android Api 2,Google Maps Api 2,Android Maps V2,我试图在googlemapsv2api中获取地图中心的经纬度&获取地图的宽度和长度 这是我的旧代码(来自我开始修改的GMAPSV1): 如何使用Android GMaps V2 API执行与mapView.getMapCenter()、mapView.getHeight()和mapView.getWidth()相同的功能?获取中心: GoogleMap map; LatLng center = map.getCameraPosition().target; 获取宽度和高度: 如果要使用Frag
GoogleMap map;
LatLng center = map.getCameraPosition().target;
获取宽度和高度:
如果要使用FragmentTransaction
将MapFragment
添加到活动中,则必须提供一些ViewGroup
以将片段放入。类似于线性布局的东西。在这样的ViewGroup
上调用getWidth()
和getHeight()
,应该可以得到您想要的
希望能有帮助。如果你需要一个例子,让我知道
编辑-添加示例:
请查看,尤其是名为:
在以开头的部分下,您还可以向代码中的活动添加MapFragment,下面是一个示例。在该示例中,R.id.my_container
正是我上面提到的ViewGroup
。在活动
的XML布局中,有如下内容:
<LinearLayout
android:id="@+id/my_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
我希望这是可以理解的。如果你能提供一个很好的例子。
<LinearLayout
android:id="@+id/my_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
LinearLayout myContainer = (LinearLayout) findViewById(R.id.my_container);
int mapHeight = myContainer.getHeight();
int mapWidth = myContainer.getWidth();