use of com.here.android.mpa.routing.RouteOptions in project here-android-sdk-examples by heremaps.
the class MapFragmentView method createRoute.
/* Creates a route from 4350 Still Creek Dr to Langley BC with highways disallowed */
private void createRoute() {
/* Initialize a CoreRouter */
CoreRouter coreRouter = new CoreRouter();
/* Initialize a RoutePlan */
RoutePlan routePlan = new RoutePlan();
/*
* Initialize a RouteOption.HERE 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) {
/* Create a MapRoute so that it can be placed on the map */
m_mapRoute = new MapRoute(routeResults.get(0).getRoute());
/* 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.
*/
GeoBoundingBox gbb = routeResults.get(0).getRoute().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: " + routingError, Toast.LENGTH_LONG).show();
}
}
});
}
use of com.here.android.mpa.routing.RouteOptions in project here-android-sdk-examples by heremaps.
the class Venue3dActivity method onCalculateRouteClick.
// Setup routing parameters and calculate route.
public void onCalculateRouteClick(View v) {
if ((startLocation == null) || (endLocation == null)) {
Toast.makeText(getApplicationContext(), "you have to set start and stop point", Toast.LENGTH_SHORT).show();
return;
}
VenueRouteOptions venueRouteOptions = new VenueRouteOptions();
RouteOptions options = venueRouteOptions.getRouteOptions();
// Set algorithm mode (fastest, shortest).
options.setRouteType(Type.values()[m_routingOptionType.getSelectedItemPosition()]);
// Set transport mode (pedestrian, car, public_transport).
options.setTransportMode(TransportMode.values()[m_routingOptionMode.getSelectedItemPosition()]);
options.setRouteCount(1);
venueRouteOptions.setRouteOptions(options);
RoutingController routingController = m_mapFragment.getRoutingController();
// This is an async function, the logic to display route is in callback
// onCombinedRouteCompleted(CombinedRoute route)
routingController.calculateCombinedRoute(startLocation, endLocation, venueRouteOptions);
}
use of com.here.android.mpa.routing.RouteOptions in project here-android-sdk-examples by heremaps.
the class MapFragmentView method calculateRoute.
private void calculateRoute(GeoCoordinate startNavPoint, GeoCoordinate endNavPoint) {
m_map.addMapObject(new MapMarker(startNavPoint));
m_map.addMapObject(new MapMarker(endNavPoint));
m_routePlan = new RoutePlan();
m_routePlan.addWaypoint(new RouteWaypoint(startNavPoint));
m_routePlan.addWaypoint(new RouteWaypoint(endNavPoint));
RouteOptions m_routeOptions = new RouteOptions();
m_routeOptions.setTransportMode(RouteOptions.TransportMode.CAR).setRouteType(RouteOptions.Type.SHORTEST);
m_routePlan.setRouteOptions(m_routeOptions);
CoreRouter m_router = new CoreRouter();
m_router.calculateRoute(m_routePlan, new RouterListener(m_activity));
}
use of com.here.android.mpa.routing.RouteOptions in project here-android-sdk-examples by heremaps.
the class BasicVenueActivity method onCalculateRouteClick.
// Setup routing parameters and calculate route.
public void onCalculateRouteClick(View v) {
if (mLastReceivedPosition != null && mSelectedVenue != null && mSelectedSpace != null) {
VenueRouteOptions venueRouteOptions = new VenueRouteOptions();
RouteOptions options = venueRouteOptions.getRouteOptions();
// Set algorithm mode shortest and transport mode pedestrian in this case
options.setRouteType(RouteOptions.Type.SHORTEST);
options.setTransportMode(RouteOptions.TransportMode.PEDESTRIAN);
options.setRouteCount(1);
venueRouteOptions.setRouteOptions(options);
VenueController selectedVenueController = mVenueMapFragment.getVenueController(mSelectedVenue);
if (selectedVenueController != null && mRoutingController != null) {
Toast.makeText(BasicVenueActivity.this, "Calculating route...", Toast.LENGTH_SHORT).show();
// Determine start location either from the venue as
// LevelLocation, or from outside as OutdoorLocation
BaseLocation startLocation;
if ((mLastReceivedPosition.getPositionSource() == GeoPosition.SOURCE_INDOOR)) {
Level startLevel = selectedVenueController.getSelectedLevel();
for (final Level level : selectedVenueController.getVenue().getLevels()) {
if (level.getFloorNumber() == mLastReceivedPosition.getFloorId()) {
startLevel = level;
break;
}
}
startLocation = new LevelLocation(startLevel, mLastReceivedPosition.getCoordinate(), selectedVenueController);
} else {
startLocation = new OutdoorLocation(mLastReceivedPosition.getCoordinate());
}
// End location is in this case always the selected space
BaseLocation endLocation = new SpaceLocation(mSelectedSpace, selectedVenueController);
// This is an async function, the logic to display route is in callback
// onCombinedRouteCompleted(CombinedRoute route)
mRoutingController.calculateCombinedRoute(startLocation, endLocation, venueRouteOptions);
}
} else {
Toast.makeText(BasicVenueActivity.this, "Unable to calculate route", Toast.LENGTH_SHORT).show();
}
}
use of com.here.android.mpa.routing.RouteOptions in project here-android-sdk-examples by heremaps.
the class RouteUtil method createRoute.
public static RoutePlan createRoute() {
/* Initialize a RoutePlan */
final 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
*/
final 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.FASTEST);
/* Calculate 1 route. */
routeOptions.setRouteCount(1);
/* Finally set the route option */
routePlan.setRouteOptions(routeOptions);
/* Define waypoints for the route */
/* START: Holländerstraße, Wedding, 13407 Berlin */
RouteWaypoint startPoint = new RouteWaypoint(new GeoCoordinate(52.562755700200796, 13.34599438123405));
/* MIDDLE: Lynarstraße 3 */
RouteWaypoint middlePoint = new RouteWaypoint(new GeoCoordinate(52.54172, 13.36354));
/* END: Agricolastraße 29, 10555 Berlin */
RouteWaypoint destination = new RouteWaypoint(new GeoCoordinate(52.520720371976495, 13.332345457747579));
/* Add both waypoints to the route plan */
routePlan.addWaypoint(startPoint);
routePlan.addWaypoint(middlePoint);
routePlan.addWaypoint(destination);
return routePlan;
}
Aggregations