我正在使用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.
如果测量了地图,是否有事件监听器?
EDIT1: @raz这是我检索地图片段的代码:
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
}
答案 0 :(得分:6)
感谢@Gavin:
,我找到了这个解决方案googleMap.setOnMapLoadedCallback(new OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
Log.i(TAG_LOG_I, "Map loaded successfully :)");
}
});