【问题标题】:Google maps DirectionApi : FATAL EXCEPTION: Rate Limited Dispatcher谷歌地图DirectionApi:致命例外:速率受限调度程序
【发布时间】:2019-12-14 22:49:41
【问题描述】:

说明:

我想使用 Google Maps Services 的 Java 客户端从 Direction api 获取结果。但是当我单击 InfoWindoclick 时,我在我的 android studio 上遇到了 FATAL EXCEPTION: Rate Limited Dispatcher 错误。请任何人帮助我。我尝试解决这个问题 2几天,但我不修复它。

我在 google 上搜索修复此问题并搜索 stackoverflow,但没有找到任何可以帮助我解决问题的解决方案。

这是 build.gradel:

apply plugin: 'com.android.application'

android {
compileSdkVersion 29
defaultConfig {
    applicationId "com.codingwithmitch.googlemaps2018"
    minSdkVersion 16
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//Android Support Design Library
implementation 'com.google.android.material:material:1.0.0'
//RecyclerView
implementation 'androidx.recyclerview:recyclerview:1.0.0'
// Support multidex
implementation 'androidx.multidex:multidex:2.0.1'
// Firebase Core
implementation 'com.google.firebase:firebase-core:17.0.1'
//Firebase Authentication
implementation 'com.google.firebase:firebase-auth:18.1.0'
// Firestore Firestore
implementation 'com.google.firebase:firebase-firestore:20.2.0'

// glide
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'

// Circle ImageView
implementation 'de.hdodenhof:circleimageview:2.2.0'

//google location
implementation 'com.google.android.gms:play-services-location:17.0.0'
//Google Play Services for Maps
implementation 'com.google.android.gms:play-services-maps:17.0.0'
//marker clustering
implementation 'com.google.maps.android:android-maps-utils:0.5'
//java library link for google directions:https://github.com/googlemaps/google-maps-services-java
implementation 'com.google.maps:google-maps-services:0.9.4'
implementation 'org.slf4j:slf4j-simple:1.7.25'
}
apply plugin: 'com.google.gms.google-services'

这是我的代码:

if(mGeoApiContext == null){
        //GeoApiContext context = new GeoApiContext().setApiKey("YOUR_API_KEY");
        mGeoApiContext = new GeoApiContext.Builder()
                .apiKey(getResources().getString(R.string.google_map_api_key))
                .build();
    }
 @Override
public void onInfoWindowClick(final Marker marker) {
    if (marker.getSnippet().equals("This is you")) {
        marker.hideInfoWindow();
    } else {

        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setMessage(marker.getSnippet())
                .setCancelable(true)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                        calculateDirections(marker);
                        dialog.dismiss();
                    }
                })
                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                        dialog.cancel();
                    }
                });
        final AlertDialog alert = builder.create();
        alert.show();
    }
}

private void calculateDirections(Marker marker){
    Log.d(TAG, "calculateDirections: calculating directions.");

    com.google.maps.model.LatLng destination = new com.google.maps.model.LatLng(
            marker.getPosition().latitude,
            marker.getPosition().longitude
    );
    DirectionsApiRequest directions = new DirectionsApiRequest(mGeoApiContext);

    directions.alternatives(true);
    directions.origin(
            new com.google.maps.model.LatLng(
                    mUserPosition.getGeoPoint().getLatitude(),
                    mUserPosition.getGeoPoint().getLongitude()
            )
    );
    Log.d(TAG, "calculateDirections: destination: " + destination.toString());
    directions.destination(destination).setCallback(new PendingResult.Callback<DirectionsResult>() {
        @Override
        public void onResult(DirectionsResult result) {
            Log.d(TAG, "calculateDirections: routes: " + result.routes[0].toString());
            Log.d(TAG, "calculateDirections: duration: " + result.routes[0].legs[0].duration);
            Log.d(TAG, "calculateDirections: distance: " + result.routes[0].legs[0].distance);
            Log.d(TAG, "calculateDirections: geocodedWayPoints: " + result.geocodedWaypoints[0].toString());

            Log.d(TAG, "onResult: successfully retrieved directions.");
            //addPolylinesToMap(result);
        }

        @Override
        public void onFailure(Throwable e) {
            Log.e(TAG, "calculateDirections: Failed to get directions: " + e.getMessage() );

        }
    });
}

这是例外:

E/AndroidRuntime: FATAL EXCEPTION: Rate Limited Dispatcher
Process: com.codingwithmitch.googlemaps2018, PID: 15839
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/ZonedDateTime;
    at com.google.maps.internal.OkHttpPendingResult.parseResponse(OkHttpPendingResult.java:241)
    at com.google.maps.internal.OkHttpPendingResult.onResponse(OkHttpPendingResult.java:207)
    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:174)
    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
    at java.lang.Thread.run(Thread.java:761)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "java.time.ZonedDateTime" on path: DexPathList[[zip file "/data/app/com.codingwithmitch.googlemaps2018-1/base.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.codingwithmitch.googlemaps2018-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.codingwithmitch.googlemaps2018-1/lib/arm, /system/lib, /vendor/lib, /system/vendor/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at com.google.maps.internal.OkHttpPendingResult.parseResponse(OkHttpPendingResult.java:241) 
    at com.google.maps.internal.OkHttpPendingResult.onResponse(OkHttpPendingResult.java:207) 
    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:174) 
    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
    at java.lang.Thread.run(Thread.java:761) 

【问题讨论】:

  • Caused by: java.lang.ClassNotFoundException: Didn't find class "java.time.ZonedDateTime" on path: DexPathList你已经用谷歌搜索了吗?
  • 是的。但我找不到适合我的项目的解决方案。
  • 解决方案告诉您该怎么做?我遇到了同样的问题,我自己解决了。我愿意为您提供解决方案,但更重要的是您要了解如何通过 Google 搜索您的问题,这样您就不必再咨询 StackOverflow 的基本问题
  • 对不起。我尝试这个原因:java.lang.ClassNotFoundException:在路径上找不到类“java.time.ZonedDateTime”:谷歌中的DexPathList,但我不知道解决方案。请帮助我。下次我会搜索在谷歌中正确然后在stackoverflow中发布问题。请帮助我。
  • 听起来不粗鲁,但我确实得到了具有完全相同查询的搜索结果,解决了问题......

标签: android android-studio google-api-java-client google-directions-api


【解决方案1】:

将以下行添加到项目的 Gradle 文件中

实施组:'com.github.seratch',名称:'java-time-backport',版本:'1.0.0'

确保在 Google Cloud 项目上启用结算

还应避免在 Android 上使用 GoogleMapsServices 库。在此处阅读更多信息https://github.com/googlemaps/google-maps-services-java/blob/master/README.md#intended-usage-of-this-library

【讨论】:

  • 实施帮助了我并挽救了我的一天
  • 不建议在 Android 应用中使用 google-maps-services...但是,添加该依赖项可以解决问题。
猜你喜欢
  • 2020-08-09
  • 2023-03-28
  • 2013-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-27
  • 1970-01-01
相关资源
最近更新 更多