Search in sources :

Example 71 with Point

use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.

the class RouteViewModel method extractCoordinatesFromOptions.

/**
 * Extracts the {@link Point} coordinates, adds a destination marker,
 * and fetches a route with the coordinates.
 *
 * @param options containing origin and destination
 */
private void extractCoordinatesFromOptions(NavigationViewOptions options) {
    if (options.origin() != null && options.destination() != null) {
        cacheRouteProfile(options);
        cacheRouteLanguage(options, null);
        Point origin = options.origin();
        destination.setValue(options.destination());
        fetchRouteFromCoordinates(origin, destination.getValue());
    }
}
Also used : Point(com.mapbox.geojson.Point)

Example 72 with Point

use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.

the class RouteViewModel method fetchRouteFromOffRouteEvent.

/**
 * Requests a new {@link DirectionsRoute}.
 * <p>
 * Will use {@link Location} bearing if we have a rawLocation with bearing.
 * <p>
 * Called when an off-route event is fired and a new {@link DirectionsRoute}
 * is needed to continue navigating.
 *
 * @param event found from off-route event
 */
public void fetchRouteFromOffRouteEvent(OffRouteEvent event) {
    if (OffRouteEvent.isValid(event)) {
        Double bearing = null;
        if (rawLocation != null) {
            bearing = rawLocation.hasBearing() ? Float.valueOf(rawLocation.getBearing()).doubleValue() : null;
        }
        Point origin = event.getNewOrigin();
        RouteProgress progress = event.getRouteProgress();
        NavigationRoute.Builder builder = buildRouteRequestFromCurrentLocation(origin, bearing, progress);
        if (builder != null) {
            addNavigationViewOptions(builder);
            builder.alternatives(true);
            builder.build().getRoute(this);
        }
    }
}
Also used : Point(com.mapbox.geojson.Point) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) NavigationRoute(com.mapbox.services.android.navigation.v5.navigation.NavigationRoute)

Aggregations

Point (com.mapbox.geojson.Point)72 Test (org.junit.Test)31 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)29 Location (android.location.Location)18 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)17 LineString (com.mapbox.geojson.LineString)15 ArrayList (java.util.ArrayList)10 LegStep (com.mapbox.api.directions.v5.models.LegStep)9 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)7 Feature (com.mapbox.geojson.Feature)4 NavigationRoute (com.mapbox.services.android.navigation.v5.navigation.NavigationRoute)4 DirectionsResponse (com.mapbox.api.directions.v5.models.DirectionsResponse)3 DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)3 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)3 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 RouteOptions (com.mapbox.api.directions.v5.models.RouteOptions)2 MarkerOptions (com.mapbox.mapboxsdk.annotations.MarkerOptions)2 BaseTest (com.mapbox.services.android.navigation.ui.v5.BaseTest)2