我无法在片段中显示地图

时间:2018-12-16 20:43:24

标签: java android android-studio maps

我想在我的let table = document.getElementById(tableID);中显示一个带有标记的地图,但是它没有显示任何地图,似乎在我运行该应用程序时不存在。

我的MainActivity中有一个Fragment,像这样:

activity_main

我有一个 <com.google.android.gms.maps.MapView android:id="@+id/mapVieww" android:layout_width="match_parent" android:layout_height="400dp" /> 文件,如下所示:

.java

我在互联网上找到了该信息。谁知道错在哪里?

1 个答案:

答案 0 :(得分:0)

首先用MapsInitializer.initialize(getActivity().getApplicationContext());删除try-catch,因为:

如果您使用的是MapFragment或MapView,并且已经通过在这两个类中调用getMapAsync()并等待onMapReady(GoogleMap map)回调而获得了(非空)GoogleMap,那么您就不必担心这个班。有关一些示例,请参见示例应用程序。 来自文档-https://developers.google.com/android/reference/com/google/android/gms/maps/MapsInitializer

其次,创建mMapView.getMapAsync(this);并将您的带有地图的工作移至OnMapReadyCallback的实现

第三:这是什么意思-mMapView.onResume(); // needed to get the map to display immediately为什么需要?

您在哪台设备上尝试?虚拟还是真实?