【问题标题】:MapFragment on measured event listener测量事件侦听器上的 MapFragment
【发布时间】: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();
}

【问题讨论】:

标签: android google-maps


【解决方案1】:

感谢@Gavin,我找到了这个解决方案:

googleMap.setOnMapLoadedCallback(new OnMapLoadedCallback() {
    @Override
    public void onMapLoaded() {
        Log.i(TAG_LOG_I, "Map loaded successfully :)");
    }
});

【讨论】:

    猜你喜欢
    • 2018-09-04
    • 2012-01-05
    • 2018-08-06
    • 1970-01-01
    • 2020-09-06
    • 2013-11-08
    • 1970-01-01
    相关资源
    最近更新 更多