【发布时间】:2014-07-20 11:13:40
【问题描述】:
我正在使用 MapFragment,我的活动布局是这样的:
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/actionbar" />
如果我想使用 CameraUpdateFactory.newLatLngBounds(LatLngBounds, padding) 移动地图相机,我会收到此错误:
Map size can't be 0. Most likely, layout has not yet occured for the map view. Either wait until layout has occurred or use newLatLngBounds(LatLngBounds, int, int, int) which allows you to specify the map's dimensions.
如果地图已测量,是否有事件监听器?
编辑1: @raz 这是我检索地图片段的代码:
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
}
【问题讨论】:
-
您能否发布您检索地图片段以及地图的代码?
-
同上,在对地图进行操作之前正确获取地图片段很重要。
-
@raz 我已经发布了代码,抱歉耽搁了。
标签: android google-maps