gpt4 book ai didi

android - IllegalArgumentException:在 Google MapView 的 zoomOut 期间宽度和高度必须 > 0

转载 作者:太空狗 更新时间:2023-10-29 16:10:24 25 4
gpt4 key购买 nike

我正在尝试在我的 Activity 的 oncreateMethod 中放大 Google MapView。每次我尝试通过 mapController 缩放 map 时,我都会收到 IllegalArgumentException:

04-15 10:16:51.012: ERROR/AndroidRuntime(528): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.client/android.client.ui.showstores.StoreMap}: java.lang.IllegalArgumentException: width and height must be > 0

如果我调用 MapController 的 zoomOut 或 zoomIn 函数,则会抛出此异常。 .遗憾的是,我使用的 zoomIn 函数没有任何参数。

我调用缩放函数的 onCreateMethod 如下所示:

    mapView = (MapView) findViewById(R.id.map);
mapView.setBuiltInZoomControls(true);
MapController mapController = mapView.getController();
mapController.zoomIn();

我在这里有点不知所措,因为我没有做任何特别的事情。

整个堆栈跟踪是:

04-15 10:16:51.012: ERROR/AndroidRuntime(528): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.client/android.client.ui.showstores.StoreMap}: java.lang.IllegalArgumentException: width and height must be > 0
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at android.os.Handler.dispatchMessage(Handler.java:99)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at android.os.Looper.loop(Looper.java:123)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at android.app.ActivityThread.main(ActivityThread.java:4203)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at java.lang.reflect.Method.invokeNative(Native Method)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at java.lang.reflect.Method.invoke(Method.java:521)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at dalvik.system.NativeStart.main(Native Method)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): Caused by: java.lang.IllegalArgumentException: width and height must be > 0
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at android.graphics.Bitmap.nativeCreate(Native Method)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at com.google.android.maps.ZoomHelper.createSnapshot(ZoomHelper.java:305)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at com.google.android.maps.ZoomHelper.doZoom(ZoomHelper.java:137)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at com.google.android.maps.ZoomHelper.doZoom(ZoomHelper.java:126)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at com.google.android.maps.MapView.doZoom(MapView.java:1459)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at com.google.android.maps.MapView.doZoom(MapView.java:1468)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at com.google.android.maps.MapController.zoomIn(MapController.java:427)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at android.client.ui.showstores.StoreMap.onCreate(StoreMap.java:58)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
04-15 10:16:51.012: ERROR/AndroidRuntime(528): ... 11 more

最佳答案

我找到了解决这种情况的方法。

   int zoomSteps = 2;

int currentLatitudeSpan = mMapView.getLatitudeSpan();
int currentLongitudeSpan = mMapView.getLongitudeSpan();

int zoomedLatitudeSpan = 2 * zoomSteps * currentLatitudeSpan;
int zoomedLongitudeSpan = 2 * zoomSteps * currentLongitudeSpan;

mMapController.zoomToSpan(zoomedLatitudeSpan, zoomedLongitudeSpan);'

这段代码将 map 缩放了两次

关于android - IllegalArgumentException:在 Google MapView 的 zoomOut 期间宽度和高度必须 > 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2643705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com