Search in sources :

Example 1 with RouteWaypoint

use of com.here.android.mpa.routing.RouteWaypoint 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 RouteWaypoint

use of com.here.android.mpa.routing.RouteWaypoint in project here-android-sdk-examples by heremaps.

the class NavigationController method calculateDefaultRoute.

private void calculateDefaultRoute(List<RouteWaypoint> waypointList) {
    Log.d(TAG, "calculateDefaultRoute() called ");
    RoutePlan routePlan = new RoutePlan();
    routePlan.setRouteOptions(defaultRouteOptions);
    for (RouteWaypoint routeWaypoint : waypointList) {
        routePlan.addWaypoint(routeWaypoint);
    }
    defeultCoreRouter.calculateRoute(routePlan, new Router.Listener<List<RouteResult>, RoutingError>() {

        @Override
        public void onProgress(int percentage) {
        // callback is used only for offline calculation
        }

        @Override
        public void onCalculateRouteFinished(@NonNull final List<RouteResult> response, @NonNull RoutingError error) {
            if (error != RoutingError.NONE || response.isEmpty()) {
                Log.e(TAG, "onDefaultCalculateRouteFinished with error " + error);
                return;
            }
            activity.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    onDefaultRouteCalculated(response.get(0).getRoute());
                }
            });
        }
    });
}
Also used : RoutingError(com.here.android.mpa.routing.RoutingError) RouteResult(com.here.android.mpa.routing.RouteResult) FTCRRouter(com.here.android.mpa.ftcr.FTCRRouter) Router(com.here.android.mpa.routing.Router) CoreRouter(com.here.android.mpa.routing.CoreRouter) ArrayList(java.util.ArrayList) List(java.util.List) RoutePlan(com.here.android.mpa.routing.RoutePlan) FTCRRoutePlan(com.here.android.mpa.ftcr.FTCRRoutePlan) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint)

Example 3 with RouteWaypoint

use of com.here.android.mpa.routing.RouteWaypoint in project here-android-sdk-examples by heremaps.

the class NavigationController method createWaypointsFromFTCRGeometry.

private List<RouteWaypoint> createWaypointsFromFTCRGeometry(List<GeoCoordinate> ftcrRouteGeometry, List<RouteWaypoint> stopoves) {
    ArrayList<RouteWaypoint> sparseFTCRGeometryAsWaypoints = new ArrayList<>();
    int lastAddedStopoverIndex = 0;
    RouteWaypoint lastAddedStopover = stopoves.get(lastAddedStopoverIndex);
    RouteWaypoint nextStopover = stopoves.get(lastAddedStopoverIndex + 1);
    sparseFTCRGeometryAsWaypoints.add(lastAddedStopover);
    for (int i = 0; i < ftcrRouteGeometry.size(); i++) {
        GeoCoordinate curr = ftcrRouteGeometry.get(i);
        if (curr.distanceTo(lastAddedStopover.getNavigablePosition()) >= MIN_DISTANCE_BETWEEN_WAYPOINTS) {
            // use VIA waypoint just to advice SDK to calculate route through this geo point
            // no any event will be triggered on reaching this type of waypoint
            lastAddedStopover = new RouteWaypoint(curr, Type.VIA_WAYPOINT);
            sparseFTCRGeometryAsWaypoints.add(lastAddedStopover);
        }
        // also find and add stopover waupoints
        if (isFTCRGeometryPointCloseToStopover(nextStopover, curr)) {
            lastAddedStopover = nextStopover;
            lastAddedStopoverIndex = lastAddedStopoverIndex + 1;
            // lastAddedStopover has STOP type, so SDK will trigger needed events in guidance
            sparseFTCRGeometryAsWaypoints.add(lastAddedStopover);
            if (lastAddedStopoverIndex + 1 < stopoves.size()) {
                nextStopover = stopoves.get(lastAddedStopoverIndex + 1);
            } else {
                nextStopover = null;
            }
        }
    }
    return sparseFTCRGeometryAsWaypoints;
}
Also used : ArrayList(java.util.ArrayList) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint)

Example 4 with RouteWaypoint

use of com.here.android.mpa.routing.RouteWaypoint in project here-android-sdk-examples by heremaps.

the class MapFragmentView method calculateAndStartNavigation.

private void calculateAndStartNavigation() {
    if (m_map == null) {
        Toast.makeText(m_activity, "Map is not ready yet", Toast.LENGTH_SHORT).show();
        return;
    }
    if (NavigationManager.getInstance().getRunningState() == NavigationManager.NavigationState.RUNNING) {
        Toast.makeText(m_activity, "Navigation is currently running", Toast.LENGTH_SHORT).show();
        return;
    }
    final RoutePlan routePlan = new RoutePlan();
    // these two waypoints cover suburban roads
    routePlan.addWaypoint(new RouteWaypoint(new GeoCoordinate(48.960497, 2.47351)));
    routePlan.addWaypoint(new RouteWaypoint(new GeoCoordinate(48.976, 2.49162)));
    // calculate a route for navigation
    CoreRouter coreRouter = new CoreRouter();
    coreRouter.calculateRoute(routePlan, new CoreRouter.Listener() {

        @Override
        public void onCalculateRouteFinished(List<RouteResult> list, RoutingError routingError) {
            if (routingError == RoutingError.NONE) {
                Route route = list.get(0).getRoute();
                m_currentRoute = new MapRoute(route);
                m_map.addMapObject(m_currentRoute);
                // move the map to the first waypoint which is starting point of
                // the route
                m_map.setCenter(routePlan.getWaypoint(0).getNavigablePosition(), Map.Animation.NONE);
                // setting MapUpdateMode to RoadView will enable automatic map
                // movements and zoom level adjustments
                NavigationManager navigationManager = NavigationManager.getInstance();
                navigationManager.setMapUpdateMode(NavigationManager.MapUpdateMode.ROADVIEW);
                // adjust tilt to show 3D view
                m_map.setTilt(80);
                // adjust transform center for navigation experience in portrait
                // view
                m_mapTransformCenter = new PointF(m_map.getTransformCenter().x, (m_map.getTransformCenter().y * 85 / 50));
                m_map.setTransformCenter(m_mapTransformCenter);
                // create a map marker to show current position
                Image icon = new Image();
                m_positionIndicatorFixed = new MapMarker();
                try {
                    icon.setImageResource(R.drawable.gps_position);
                    m_positionIndicatorFixed.setIcon(icon);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                m_positionIndicatorFixed.setVisible(true);
                m_positionIndicatorFixed.setCoordinate(m_map.getCenter());
                m_map.addMapObject(m_positionIndicatorFixed);
                m_mapFragment.getPositionIndicator().setVisible(false);
                navigationManager.setMap(m_map);
                // listen to real position updates. This is used when RoadView is
                // not active.
                PositioningManager.getInstance().addListener(new WeakReference<>(mapPositionHandler));
                // listen to updates from RoadView which tells you where the map
                // center should be situated. This is used when RoadView is active.
                navigationManager.getRoadView().addListener(new WeakReference<>(roadViewListener));
                // listen to navigation manager events.
                navigationManager.addNavigationManagerEventListener(new WeakReference<>(navigationManagerEventListener));
                navigationManager.addLaneInformationListener(new WeakReference<>(m_laneInformationListener));
                // start navigation simulation travelling at 13 meters per second
                navigationManager.simulate(route, 13);
            } else {
                Toast.makeText(m_activity, "Error:route calculation returned error code: " + routingError, Toast.LENGTH_LONG).show();
            }
        }

        @Override
        public void onProgress(int i) {
        }
    });
}
Also used : MapRoute(com.here.android.mpa.mapping.MapRoute) NavigationManager(com.here.android.mpa.guidance.NavigationManager) MapMarker(com.here.android.mpa.mapping.MapMarker) PointF(android.graphics.PointF) CoreRouter(com.here.android.mpa.routing.CoreRouter) GeoCoordinate(com.here.android.mpa.common.GeoCoordinate) IOException(java.io.IOException) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) Image(com.here.android.mpa.common.Image) RouteWaypoint(com.here.android.mpa.routing.RouteWaypoint) RoutingError(com.here.android.mpa.routing.RoutingError) RouteResult(com.here.android.mpa.routing.RouteResult) WeakReference(java.lang.ref.WeakReference) RoutePlan(com.here.android.mpa.routing.RoutePlan) Route(com.here.android.mpa.routing.Route) MapRoute(com.here.android.mpa.mapping.MapRoute)

Example 5 with RouteWaypoint

use of com.here.android.mpa.routing.RouteWaypoint 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)

Aggregations

RouteWaypoint (com.here.android.mpa.routing.RouteWaypoint)12 GeoCoordinate (com.here.android.mpa.common.GeoCoordinate)9 CoreRouter (com.here.android.mpa.routing.CoreRouter)9 RoutePlan (com.here.android.mpa.routing.RoutePlan)9 RouteResult (com.here.android.mpa.routing.RouteResult)7 RoutingError (com.here.android.mpa.routing.RoutingError)7 List (java.util.List)7 MapRoute (com.here.android.mpa.mapping.MapRoute)6 RouteOptions (com.here.android.mpa.routing.RouteOptions)6 Router (com.here.android.mpa.routing.Router)5 ArrayList (java.util.ArrayList)5 GeoBoundingBox (com.here.android.mpa.common.GeoBoundingBox)3 Route (com.here.android.mpa.routing.Route)3 OnEngineInitListener (com.here.android.mpa.common.OnEngineInitListener)2 FTCRRoutePlan (com.here.android.mpa.ftcr.FTCRRoutePlan)2 FTCRRouter (com.here.android.mpa.ftcr.FTCRRouter)2 Map (com.here.android.mpa.mapping.Map)2 MapMarker (com.here.android.mpa.mapping.MapMarker)2 PointF (android.graphics.PointF)1 NonNull (androidx.annotation.NonNull)1