【发布时间】:2014-07-27 22:21:43
【问题描述】:
有人能够让 Google MapView V2 工作吗?我浏览了 StackOverflow(包括这个问题:Android MapView getMap() returns null),每个人似乎都无法使用 MapView,最终不得不使用 Fragment。
具有以下 google_map_view.xml:
<com.google.android.gms.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
我尝试以这种方式实例化地图:
LayoutInflater layoutInflater = (LayoutInflater) getSystemService( Context.LAYOUT_INFLATER_SERVICE );
googleMapView = (View) layoutInflater.inflate(R.layout.google_map_view, null);
MapView mapView = (MapView)googleMapView.findViewById(R.id.map_view);
GoogleMap googleMap = mapView.getMap();
googleMap 将为空。
Google Play 服务与应用程序正确关联,并且我在 AndroidManifest.xml 文件中拥有正确的密钥。
想法?
【问题讨论】:
-
在尝试检索
GoogleMap之前,尝试在MapView上调用onCreate(),看看是否有帮助。您也可以暂时尝试使用MapFragment——即使您不打算长期使用MapFragment,也可能有助于解决与地图V2 相关的其他应用程序的任何配置问题。 -
mapView.getMap() 再往下一点。就像在 onActivityStarted()
-
我尝试了这两种方法,但没有任何乐趣。我将不得不使用 MapFragment 方法,即使它涉及到相当多的返工。谷歌将这种机制放在那里是非常令人恼火的,但它在看似最简单的情况下不起作用。谢谢大家的建议。
标签: android google-maps android-mapview android-maps-v2