Search in sources :

Example 1 with RouteOptions

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();
            }
        }
    });
}
Also used : MapRoute(com.here.android.mpa.mapping.MapRoute) CoreRouter(com.here.android.mpa.routing.CoreRouter) CoreRouter(com.here.android.mpa.routing.CoreRouter) Router(com.here.android.mpa.routing.Router) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) RouteOptions(com.here.android.mpa.routing.RouteOptions) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) RoutingError(com.here.android.mpa.routing.RoutingError) RouteResult(com.here.android.mpa.routing.RouteResult) List(java.util.List) RoutePlan(com.here.android.mpa.routing.RoutePlan) GeoBoundingBox(com.here.android.mpa.common.GeoBoundingBox)

Example 2 with RouteOptions

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);
}
Also used : RoutingController(com.here.android.mpa.venues3d.RoutingController) VenueRouteOptions(com.here.android.mpa.venues3d.VenueRouteOptions) VenueRouteOptions(com.here.android.mpa.venues3d.VenueRouteOptions) RouteOptions(com.here.android.mpa.routing.RouteOptions)

Example 3 with RouteOptions

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));
}
Also used : MapMarker(com.here.android.mpa.mapping.MapMarker) CoreRouter(com.here.android.mpa.routing.CoreRouter) RoutePlan(com.here.android.mpa.routing.RoutePlan) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) RouteOptions(com.here.android.mpa.routing.RouteOptions)

Example 4 with RouteOptions

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();
    }
}
Also used : LevelLocation(com.here.android.mpa.venues3d.LevelLocation) SpaceLocation(com.here.android.mpa.venues3d.SpaceLocation) VenueController(com.here.android.mpa.venues3d.VenueController) VenueRouteOptions(com.here.android.mpa.venues3d.VenueRouteOptions) Level(com.here.android.mpa.venues3d.Level) OutdoorLocation(com.here.android.mpa.venues3d.OutdoorLocation) VenueRouteOptions(com.here.android.mpa.venues3d.VenueRouteOptions) RouteOptions(com.here.android.mpa.routing.RouteOptions) BaseLocation(com.here.android.mpa.venues3d.BaseLocation)

Example 5 with RouteOptions

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;
}
Also used : GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) RoutePlan(com.here.android.mpa.routing.RoutePlan) RouteOptions(com.here.android.mpa.routing.RouteOptions) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint)

Aggregations

RouteOptions (com.here.android.mpa.routing.RouteOptions)9 RoutePlan (com.here.android.mpa.routing.RoutePlan)6 RouteWaypoint (com.here.android.mpa.routing.RouteWaypoint)6 GeoCoordinate (com.here.android.mpa.common.GeoCoordinate)5 CoreRouter (com.here.android.mpa.routing.CoreRouter)5 MapRoute (com.here.android.mpa.mapping.MapRoute)4 RouteResult (com.here.android.mpa.routing.RouteResult)4 Router (com.here.android.mpa.routing.Router)4 RoutingError (com.here.android.mpa.routing.RoutingError)4 List (java.util.List)4 VenueRouteOptions (com.here.android.mpa.venues3d.VenueRouteOptions)2 GeoBoundingBox (com.here.android.mpa.common.GeoBoundingBox)1 GeoPolygon (com.here.android.mpa.common.GeoPolygon)1 RoadElement (com.here.android.mpa.common.RoadElement)1 FTCRRouteOptions (com.here.android.mpa.ftcr.FTCRRouteOptions)1 MapMarker (com.here.android.mpa.mapping.MapMarker)1 DynamicPenalty (com.here.android.mpa.routing.DynamicPenalty)1 Route (com.here.android.mpa.routing.Route)1 BaseLocation (com.here.android.mpa.venues3d.BaseLocation)1 Level (com.here.android.mpa.venues3d.Level)1