Salve a tutti.
Sto provando ad usare la libreria mapbox per inglobare un navigatore nella mia app.
Ho usato il codice dell'esempio ma ottengo l'errore in oggetto.
Ecco il codice:
Gradle:
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 24
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 = 1.8
targetCompatibility = 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.material:material:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:8.6.2'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v8:0.7.0'
implementation 'com.squareup.retrofit2:converter-gson:2.7.1'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.mcxiaoke.volley:library:1.0.19'
}
dependencies {
implementation 'androidx.preference:preference:1.1+'
}
dependencies {
implementation 'androidx.appcompat:appcompat:+'
implementation 'androidx.constraintlayout:constraintlayout:+'
implementation 'com.google.android.material:material:+'
}
dependencies {
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.42.4'
}
Queste sono tutte le librerie importate:
package com.example.myapplication;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.mapbox.android.core.permissions.PermissionsListener;
import com.mapbox.android.core.permissions.PermissionsManager;
import com.mapbox.geojson.Feature;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.location.LocationComponent;
import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions;
import com.mapbox.mapboxsdk.location.modes.CameraMode;
import com.mapbox.mapboxsdk.location.modes.RenderMode;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.Style;
import com.mapbox.mapboxsdk.style.layers.PropertyFactory;
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
import com.mapbox.services.android.navigation.ui.v5.NavigationLauncher;
import com.mapbox.services.android.navigation.ui.v5.NavigationLauncherOptions;
import com.mapbox.services.android.navigation.v5.navigation.NavigationRoute;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
Porzione di codice che mi da l'errore
final Button button = findViewById(R.id.buttonNaviga); //Naviga verso....
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Point origin = Point.fromLngLat(-77.03613, 38.90992);
Point destination = Point.fromLngLat(-77.0365, 38.8977);
NavigationRoute.Builder builder = NavigationRoute.builder(context);
builder.accessToken(MAPBOX_ACCESS_TOKEN);
builder.origin(origin);
builder.destination(destination);
NavigationRoute route = builder.build();
// Call this method with Context from within an Activity
boolean simulateRoute = true;
// Create a NavigationLauncherOptions object to package everything together
NavigationLauncherOptions.Builder builder1 = NavigationLauncherOptions.builder();
builder1.directionsRoute(route);
builder1.shouldSimulateRoute(simulateRoute);
NavigationLauncherOptions options = builder1.build();
// Call this method with Context from within an Activity
NavigationLauncher.startNavigation(MainActivity.this, options);
}
});
infatti proprio nella riga di codice "builder1.directionsRoute(route);" ricevo l'errore "error: incompatible types: NavigationRoute cannot be converted to DirectionsRoute"
Chi mi può aiutare?
Grazie e saluti a tutti.