我在自己的片段(android.support.v4.app.Fragment)中使用com.google.android.gms.maps.MapView,如下所示:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.fragments.MapsFragment">
<com.google.android.gms.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map_view" />
</FrameLayout>
我遇到了问题,只有在第一次运行时,我在设备上运行应用程序才会调用onMapReady回调两次。当我停止应用并再次运行时,这不会再发生。代码:
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_maps, container, false);
mMapView = (MapView) v.findViewById(R.id.map_view);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(this);
[...]
return v;
}
此外,我将这些回调视为地图视图:onResume,onPause,onDestroy,onLowMemory。我不在其他任何地方使用mMapView变量。
有什么想法吗?我在MapView实现中做错了吗?
谢谢!
答案 0 :(得分:0)
删除此行:
(float)
如果您像mMapView.getMapAsync(this);
一样使用它,它将被自动调用。