use of com.here.android.mpa.routing.RouteResult in project here-android-sdk-examples by heremaps.
the class MapFragmentView method createRoute.
private void createRoute() {
/* Initialize a CoreRouter */
CoreRouter coreRouter = new CoreRouter();
/* Initialize a RoutePlan */
RoutePlan routePlan = new RoutePlan();
/*
* 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
*/
RouteOptions routeOptions = new RouteOptions();
/* Other transport modes are also available e.g Pedestrian */
routeOptions.setTransportMode(RouteOptions.TransportMode.CAR);
/* Disable highway in this route. */
routeOptions.setHighwaysAllowed(false);
/* Calculate the shortest route available. */
routeOptions.setRouteType(RouteOptions.Type.SHORTEST);
/* Calculate 1 route. */
routeOptions.setRouteCount(1);
/* Finally set the route option */
routePlan.setRouteOptions(routeOptions);
/* Define waypoints for the route */
/* START: 4350 Still Creek Dr */
RouteWaypoint startPoint = new RouteWaypoint(new GeoCoordinate(49.259149, -123.008555));
/* END: Langley BC */
RouteWaypoint destination = new RouteWaypoint(new GeoCoordinate(49.073640, -122.559549));
/* Add both waypoints to the route plan */
routePlan.addWaypoint(startPoint);
routePlan.addWaypoint(destination);
/* Trigger the route calculation,results will be called back via the listener */
coreRouter.calculateRoute(routePlan, new Router.Listener<List<RouteResult>, RoutingError>() {
@Override
public void onProgress(int i) {
/* The calculation progress can be retrieved in this callback. */
}
@Override
public void onCalculateRouteFinished(List<RouteResult> routeResults, RoutingError routingError) {
/* Calculation is done.Let's handle the result */
if (routingError == RoutingError.NONE) {
if (routeResults.get(0).getRoute() != null) {
m_route = routeResults.get(0).getRoute();
/* Create a MapRoute so that it can be placed on the map */
MapRoute mapRoute = new MapRoute(routeResults.get(0).getRoute());
/* Show the maneuver number on top of the route */
mapRoute.setManeuverNumberVisible(true);
/* Add the MapRoute to the map */
m_map.addMapObject(mapRoute);
/*
* We may also want to make sure the map view is orientated properly
* so the entire route can be easily seen.
*/
m_geoBoundingBox = routeResults.get(0).getRoute().getBoundingBox();
m_map.zoomTo(m_geoBoundingBox, Map.Animation.NONE, Map.MOVE_PRESERVE_ORIENTATION);
startNavigation();
} 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: " + routingError, Toast.LENGTH_LONG).show();
}
}
});
}
use of com.here.android.mpa.routing.RouteResult in project here-android-sdk-examples by heremaps.
the class MainActivity method calculateRoute.
private void calculateRoute() {
/* Initialize a CoreRouter */
m_coreRouter = new CoreRouter();
/* For calculating traffic on the m_route */
DynamicPenalty dynamicPenalty = new DynamicPenalty();
dynamicPenalty.setTrafficPenaltyMode(Route.TrafficPenaltyMode.OPTIMAL);
m_coreRouter.setDynamicPenalty(dynamicPenalty);
final RoutePlan routePlan = RouteUtil.createRoute();
m_coreRouter.calculateRoute(routePlan, new RouteUtil.RouteListener<List<RouteResult>, RoutingError>() {
@Override
public void onCalculateRouteFinished(List<RouteResult> routeResults, RoutingError routingError) {
/* Calculation is done. Let's handle the result */
if (routingError == RoutingError.NONE) {
/* Get route fro results */
m_route = routeResults.get(0).getRoute();
/* check if map route is already on map and if it is,
delete it.
*/
if (m_mapRoute != null) {
m_map.removeMapObject(m_mapRoute);
}
/* Create a MapRoute so that it can be placed on the map */
m_mapRoute = new MapRoute(routeResults.get(0).getRoute());
/* Add the MapRoute 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.
*/
m_map.zoomTo(m_route.getBoundingBox(), Map.Animation.NONE, 15);
/* Get TTA */
calculateTta();
calculateTtaUsingDownloadedTraffic();
} else {
Toast.makeText(getApplicationContext(), routingError.name(), Toast.LENGTH_SHORT).show();
}
}
});
}
use of com.here.android.mpa.routing.RouteResult in project here-android-sdk-examples by heremaps.
the class MapFragmentView method createRoute.
private void createRoute(final List<RoutingZone> excludedRoutingZones) {
/* Initialize a CoreRouter */
CoreRouter coreRouter = new CoreRouter();
/* Initialize a RoutePlan */
RoutePlan routePlan = new RoutePlan();
/*
* 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
*/
RouteOptions routeOptions = new RouteOptions();
/* Other transport modes are also available e.g Pedestrian */
routeOptions.setTransportMode(RouteOptions.TransportMode.CAR);
/* Disable highway in this route. */
routeOptions.setHighwaysAllowed(false);
/* Calculate the shortest route available. */
routeOptions.setRouteType(RouteOptions.Type.SHORTEST);
/* Calculate 1 route. */
routeOptions.setRouteCount(1);
/* Exclude routing zones. */
if (!excludedRoutingZones.isEmpty()) {
routeOptions.excludeRoutingZones(toStringIds(excludedRoutingZones));
}
if (m_addAvoidedAreas) {
DynamicPenalty dynamicPenalty = new DynamicPenalty();
// There are two option to avoid certain areas during routing
// 1. Add banned area using addBannedArea API
GeoPolygon geoPolygon = new GeoPolygon();
geoPolygon.add(Arrays.asList(new GeoCoordinate(52.631692, 13.437591), new GeoCoordinate(52.631905, 13.437787), new GeoCoordinate(52.632577, 13.438357)));
// Note, the maximum supported number of banned areas is 20.
dynamicPenalty.addBannedArea(geoPolygon);
// 1. Add banned road link using addRoadPenalty API
// Note, map data needs to be present to get RoadElement by the GeoCoordinate.
RoadElement roadElement = RoadElement.getRoadElement(new GeoCoordinate(52.406611, 13.194916), "MAC");
if (roadElement != null) {
dynamicPenalty.addRoadPenalty(roadElement, DrivingDirection.DIR_BOTH, 0);
}
coreRouter.setDynamicPenalty(dynamicPenalty);
}
/* Finally set the route option */
routePlan.setRouteOptions(routeOptions);
/* Define waypoints for the route */
/* START: South of Berlin */
RouteWaypoint startPoint = new RouteWaypoint(new GeoCoordinate(52.406425, 13.193975));
/* END: North of Berlin */
RouteWaypoint destination = new RouteWaypoint(new GeoCoordinate(52.638623, 13.441998));
/* Add both waypoints to the route plan */
routePlan.addWaypoint(startPoint);
routePlan.addWaypoint(destination);
/* Trigger the route calculation,results will be called back via the listener */
coreRouter.calculateRoute(routePlan, new Router.Listener<List<RouteResult>, RoutingError>() {
@Override
public void onProgress(int i) {
/* The calculation progress can be retrieved in this callback. */
}
@Override
public void onCalculateRouteFinished(List<RouteResult> routeResults, RoutingError routingError) {
/* Calculation is done. Let's handle the result */
if (routingError == RoutingError.NONE) {
Route route = routeResults.get(0).getRoute();
if (m_isExcludeRoutingZones && excludedRoutingZones.isEmpty()) {
// Here we exclude all available routing zones in the route.
// Also RoutingZoneRestrictionsChecker can be used to get
// available routing zones for specific RoadElement.
createRoute(route.getRoutingZones());
} else {
/* Create a MapRoute so that it can be placed on the map */
m_mapRoute = new MapRoute(route);
/* Show the maneuver number on top of the route */
m_mapRoute.setManeuverNumberVisible(true);
/* Add the MapRoute 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.
*/
m_map.zoomTo(route.getBoundingBox(), Map.Animation.NONE, Map.MOVE_PRESERVE_ORIENTATION);
}
} else {
Toast.makeText(m_activity, "Error:route calculation returned error code: " + routingError, Toast.LENGTH_LONG).show();
}
}
});
}
Aggregations