gpt4 book ai didi

java - 将折线添加到 map 错误失败解决: Ljava/time/ZonedDateTime

转载 作者:行者123 更新时间:2023-12-05 00:20:18 25 4
gpt4 key购买 nike

我正在尝试将折线添加到当前位置和动态添加到 map 的标记之间的 map 。它应该工作的方式是,当按下标记的 InfoWindow 时,会打开一个对话框,询问您是否要前往该点,当按下"is"选项时,它应该将折线添加到那一点。

信息窗口点击:

public void onInfoWindowClick(final Marker marker1) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Doriți să mergeți la această alertă?")
.setCancelable(true)
.setPositiveButton("Da", new DialogInterface.OnClickListener() {
public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
ScoateMarkerRute();
markerSelectat=marker1;
layout_confirmare.setVisibility(GONE);
layout_validare.setVisibility(GONE);
calculateDirections(marker1);
dialog.dismiss();
}
})
.setNegativeButton("Nu", 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 destinatie = 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(
locatie_user.latitude,
locatie_user.longitude
)
);
Log.d(TAG, "calculateDirections: destination: " + destinatie.toString());
directions.destination(destinatie).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.inMeters);
Log.d(TAG, "calculateDirections: geocodedWayPoints: " + result.geocodedWaypoints[0].toString());
addPolylinesToMap(result);
}

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

}
});
}

添加多段线到 map :

private void addPolylinesToMap(final DirectionsResult result){
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Log.d(TAG, "run: result routes: " + result.routes.length);
if(mPolylinesData.size()>0){
for(PolylineData polylineData: mPolylinesData){
polylineData.getPolyline().remove();
}
mPolylinesData.clear();
mPolylinesData= new ArrayList<>();
}
for(DirectionsRoute route: result.routes){
Log.d(TAG, "run: leg: " + route.legs[0].toString());
List<com.google.maps.model.LatLng> decodedPath = PolylineEncoding.decode(route.overviewPolyline.getEncodedPath());

List<LatLng> newDecodedPath = new ArrayList<>();

// This loops through all the LatLng coordinates of ONE polyline.
for(com.google.maps.model.LatLng latLng: decodedPath){
Log.d(TAG, "run: latlng: " + latLng.toString());

newDecodedPath.add(new LatLng(
latLng.lat,
latLng.lng
));
}
Polyline polyline = mMap.addPolyline(new PolylineOptions().addAll(newDecodedPath));
polyline.setColor(ContextCompat.getColor(Harta.this, R.color.scope_systems_gri));
polyline.setWidth(25);
polyline.setClickable(true);
polyline.setTag("A");
mPolylinesData.add(new PolylineData(polyline, route.legs[0]));
onPolylineClick(polyline);
zoomRoute(polyline.getPoints());
markerSelectat.setVisible(false);
}
}
});
}

当我实现这种添加折线的方法时,我使用了一张充满标记的 map ,并且确实有效。当我更改并仅添加 1 个标记时,应用程序不断崩溃并出现错误:

> > 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.example.aplicatieprimarie-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.aplicatieprimarie-2/lib/x86,
> /system/lib, /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)

编辑:添加了 build.gradle

我已经更新了:-'com.google.android.libraries.places:places-compat:2.1.0''com.google.android.libraries.places:places-compat:2.1.1' 现在同步后,当我尝试运行时,出现以下错误:

Caused by: com.android.tools.r8.utils.AbortException: Error: null, Cannot fit requested classes in a single dex file (# methods: 66003 > 65536)

build.gradle(应用程序):

apply plugin: 'com.android.application'

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

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.facebook.android:facebook-android-sdk:5.9.0'
implementation "com.google.android.gms:play-services-location:17.0.0"
implementation 'de.hdodenhof:circleimageview:3.0.1'
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.2.1'
implementation 'androidx.navigation:navigation-ui:2.2.1'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.libraries.places:places-compat:2.2.0'
implementation 'androidx.biometric:biometric:1.0.1'
implementation 'com.google.maps:google-maps-services:0.10.2'
implementation 'org.slf4j:slf4j-simple:1.7.25'
}

最佳答案

根据 Google Maps Services 的文档,这不是为 android 设计的。

The Java Client for Google Maps Services is designed for use in serverapplications. This library is not intended for use inside of anAndroid app, due to the potential for loss of API keys.

要求

  • Java 1.8 或更高版本。
  • Google map API key 。

您需要java.time来处理时区API。作为解决方法,您可以使用以下依赖项,即 java.time 包 API

的 Backport
implementation group: 'com.github.seratch', name: 'java-time-backport', version: '1.0.0'

关于java - 将折线添加到 map 错误失败解决: Ljava/time/ZonedDateTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60314607/

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