Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android GMaps v2-获取地图中心的位置&;地图高度和宽度_Java_Android_Google Maps Android Api 2_Google Maps Api 2_Android Maps V2 - Fatal编程技术网

Java Android GMaps v2-获取地图中心的位置&;地图高度和宽度

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

我试图在googlemapsv2api中获取地图中心的经纬度&获取地图的宽度和长度

这是我的旧代码(来自我开始修改的GMAPSV1):

如何使用Android GMaps V2 API执行与mapView.getMapCenter()、mapView.getHeight()和mapView.getWidth()相同的功能?

获取中心:

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();