Search in sources :

Example 1 with FTCRRoutePlan

use of com.here.android.mpa.ftcr.FTCRRoutePlan in project here-android-sdk-examples by heremaps.

the class NavigationController method calculateFTCRRoute.

private void calculateFTCRRoute(final List<RouteWaypoint> waypointList) {
    FTCRRoutePlan ftcrRoutePlan = new FTCRRoutePlan(waypointList, ftcrRouteOptions);
    ftcrRoutingTask = ftcrRouter.calculateRoute(ftcrRoutePlan, new FTCRRouter.Listener() {

        @Override
        public void onCalculateRouteFinished(@NonNull final List<FTCRRoute> routes, @NonNull FTCRRouter.ErrorResponse error) {
            if (error.getErrorCode() != RoutingError.NONE || routes.isEmpty()) {
                Log.e(TAG, "onFTCRCalculateRouteFinished with error " + error.getMessage() + ", " + error.getErrorCode());
                return;
            }
            activity.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    onFTCRRouteCalculated(routes.get(0), waypointList);
                }
            });
        }
    });
}
Also used : RerouteListener(com.here.android.mpa.guidance.NavigationManager.RerouteListener) OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener) NavigationManagerEventListener(com.here.android.mpa.guidance.NavigationManager.NavigationManagerEventListener) NonNull(androidx.annotation.NonNull) FTCRRoutePlan(com.here.android.mpa.ftcr.FTCRRoutePlan) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with FTCRRoutePlan

use of com.here.android.mpa.ftcr.FTCRRoutePlan in project here-android-sdk-examples by heremaps.

the class MapFragmentView method calculateRoute.

private void calculateRoute() {
    /*
         * Initialize a RouteOption. HERE Mobile SDK allow users to define their own parameters
         * for the route calculation, including transport modes, route types and
         * route restrictions etc. Please refer to API doc for full list of APIs
         */
    FTCRRouteOptions routeOptions = new FTCRRouteOptions();
    /* Other transport modes are also available e.g Pedestrian */
    routeOptions.setTransportMode(FTCRRouteOptions.TransportMode.CAR);
    /* Calculate the shortest route available. */
    routeOptions.setRouteType(FTCRRouteOptions.Type.SHORTEST);
    /* Define waypoints for the route */
    RouteWaypoint startPoint = new RouteWaypoint(m_startPoint);
    RouteWaypoint destination = new RouteWaypoint(m_endPoint);
    /* Initialize a RoutePlan */
    List<RouteWaypoint> routePoints = new ArrayList<>();
    routePoints.add(startPoint);
    routePoints.add(destination);
    FTCRRoutePlan routePlan = new FTCRRoutePlan(routePoints, routeOptions);
    /*
          Set the name of the map overlay. It has to be the same that is used for uploading
          the custom roads to the fleet telematics server.
         */
    routePlan.setOverlay(OVERLAY_NAME);
    if (m_routeTask != null) {
        m_routeTask.cancel();
    }
    m_routeTask = m_router.calculateRoute(routePlan, new FTCRRouter.Listener() {

        @Override
        public void onCalculateRouteFinished(@NonNull List<FTCRRoute> routeResults, @NonNull FTCRRouter.ErrorResponse errorResponse) {
            /* Calculation is done. Let's handle the result */
            if (errorResponse.getErrorCode() == RoutingError.NONE) {
                if (routeResults.get(0) != null) {
                    /* Create a FTCRMapRoute so that it can be placed on the map */
                    m_mapRoute = new FTCRMapRoute(routeResults.get(0));
                    /* Add the FTCRMapRoute to the map */
                    m_map.addMapObject(m_mapRoute);
                    /*
                         * We may also want to make sure the map view is orientated properly
                         * so the entire route can be easily seen.
                         */
                    GeoBoundingBox gbb = routeResults.get(0).getBoundingBox();
                    m_map.zoomTo(gbb, Map.Animation.NONE, Map.MOVE_PRESERVE_ORIENTATION);
                } else {
                    Toast.makeText(m_activity, "Error:route results returned is not valid", Toast.LENGTH_LONG).show();
                }
            } else {
                Toast.makeText(m_activity, "Error:route calculation returned error code: " + errorResponse.getErrorCode() + ",\nmessage: " + errorResponse.getMessage(), Toast.LENGTH_LONG).show();
            }
        }
    });
}
Also used : OnEngineInitListener(com.here.android.mpa.common.OnEngineInitListener) FTCRMapRoute(com.here.android.mpa.mapping.FTCRMapRoute) NonNull(androidx.annotation.NonNull) ArrayList(java.util.ArrayList) FTCRRoutePlan(com.here.android.mpa.ftcr.FTCRRoutePlan) ArrayList(java.util.ArrayList) List(java.util.List) FTCRRouteOptions(com.here.android.mpa.ftcr.FTCRRouteOptions) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) GeoBoundingBox(com.here.android.mpa.common.GeoBoundingBox)

Aggregations

NonNull (androidx.annotation.NonNull)2 OnEngineInitListener (com.here.android.mpa.common.OnEngineInitListener)2 FTCRRoutePlan (com.here.android.mpa.ftcr.FTCRRoutePlan)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 GeoBoundingBox (com.here.android.mpa.common.GeoBoundingBox)1 FTCRRouteOptions (com.here.android.mpa.ftcr.FTCRRouteOptions)1 NavigationManagerEventListener (com.here.android.mpa.guidance.NavigationManager.NavigationManagerEventListener)1 RerouteListener (com.here.android.mpa.guidance.NavigationManager.RerouteListener)1 FTCRMapRoute (com.here.android.mpa.mapping.FTCRMapRoute)1 RouteWaypoint (com.here.android.mpa.routing.RouteWaypoint)1