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();
}
}
});
}
Aggregations