Search in sources :

Example 1 with FTCRMapRoute

use of com.here.android.mpa.mapping.FTCRMapRoute 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)1 GeoBoundingBox (com.here.android.mpa.common.GeoBoundingBox)1 OnEngineInitListener (com.here.android.mpa.common.OnEngineInitListener)1 FTCRRouteOptions (com.here.android.mpa.ftcr.FTCRRouteOptions)1 FTCRRoutePlan (com.here.android.mpa.ftcr.FTCRRoutePlan)1 FTCRMapRoute (com.here.android.mpa.mapping.FTCRMapRoute)1 RouteWaypoint (com.here.android.mpa.routing.RouteWaypoint)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1