既然最终的SDK已经推出google apis - 使用MapView创建片段的最佳方法是什么?MapView需要MapActivity才能正常工作.
让管理片段的Activity继承自MapActivity(糟糕的解决方案,因为它违背了Fragments自包含的想法)并使用常规的基于xml的布局不起作用.我在MapActivity.setupMapView()中得到一个NullPointerException:
E/AndroidRuntime( 597): Caused by: java.lang.NullPointerException E/AndroidRuntime( 597): at com.google.android.maps.MapActivity.setupMapView(MapActivity.java:400) E/AndroidRuntime( 597): at com.google.android.maps.MapView.(MapView.java:289) E/AndroidRuntime( 597): at com.google.android.maps.MapView.(MapView.java:264) E/AndroidRuntime( 597): at com.google.android.maps.MapView.(MapView.java:247)
我的第二个想法是以编程方式创建MapView并将关联的活动(通过getActivity())作为Context传递给MapView构造函数.不起作用:
E/AndroidRuntime( 834): Caused by: java.lang.IllegalArgumentException: MapViews can only be created inside instances of MapActivity. E/AndroidRuntime( 834): at com.google.android.maps.MapView.(MapView.java:291) E/AndroidRuntime( 834): at com.google.android.maps.MapView.(MapView.java:235) E/AndroidRuntime( 834): at de.foo.FinderMapFragment.onCreateView(FinderMapFragment.java:225) E/AndroidRuntime( 834): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:708) E/AndroidRuntime( 834): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:900) E/AndroidRuntime( 834): at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:978) E/AndroidRuntime( 834): at android.app.Activity.onCreateView(Activity.java:4090) E/AndroidRuntime( 834): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:664)
真的应该有类似MapFragment的东西来处理MapView需要的后台线程我猜...那么目前最好的做法是什么呢?
感谢和问候来自德国,Valentin
android google-maps android-maps android-fragments android-3.0-honeycomb
我已经检查并仔细检查了我在Google控制台上注册的API密钥但是我仍然收到以下错误:
12-05 16:31:12.940: E/Google Maps Android API(12334): Failed to load map. Could not contact Google servers.
Run Code Online (Sandbox Code Playgroud)
我所看到的是放大/缩小按钮和MapView的背景但没有Map ??? !!!
有任何想法吗???
回答
我将在此发布,因为解决了我的问题的原因已在下面接受的答案的评论中说明.
这是READ_GSERVICES许可.出于某种原因,在开发人员网站上使用它们时未提及该权限.