我正在使用“com.google.android.gms.maps.MapFragment”在嵌入的片段中显示地图。当我尝试关闭活动(或等待几秒钟)时,应用程序崩溃并出现以下错误:
E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalArgumentException: Service not registered: com.google.android.gms.common.internal.bf@5368ecf4
at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:921)
at android.app.ContextImpl.unbindService(ContextImpl.java:1459)
at android.content.ContextWrapper.unbindService(ContextWrapper.java:484)
at com.google.android.gms.common.stats.c.a(SourceFile:145)
at com.google.android.gms.common.internal.bc.handleMessage(SourceFile:208)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
我甚至尝试使用try / catch启动地图片段:
try {
GoogleMapOptions options = new GoogleMapOptions();
options.zoomControlsEnabled(true);
mMapFragment = MapFragment.newInstance(options);
FragmentTransaction fragmentTransaction =
getFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.map, mMapFragment);
fragmentTransaction.commit();
mMapFragment.getMapAsync(this);
} catch (IllegalArgumentException e) {
Log.e(application.DEBUG_STRING, "error: ", e);
}
和
public void onMapReady(GoogleMap googleMap) {
try {
if (longitude > 0 && latitude > 0) {
markers = new ArrayList<MarkerOptions>();
MarkerOptions parkingPosition = new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title(getString(R.string.positionOfCar));
googleMap.addMarker(parkingPosition);
markers.add(parkingPosition);
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (MarkerOptions marker : markers) {
builder.include(marker.getPosition());
}
LatLngBounds bounds = builder.build();
int padding = 10; // offset from edges of the map in pixels
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
// googleMap.moveCamera(cu);
// googleMap.animateCamera(cu);
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(bounds.getCenter(), 10));
googleMap.moveCamera(CameraUpdateFactory.zoomTo(17));
Log.d(application.DEBUG_STRING, "zoom " + googleMap.getCameraPosition().zoom);
if (googleMap.getCameraPosition().zoom >= 18) {
googleMap.animateCamera(CameraUpdateFactory.zoomTo(17));
}
}
} catch (IllegalArgumentException e) {
Log.e(application.DEBUG_STRING, "error: ", e);
}
}
有人有想法解决这个问题吗?