How to detect if user has reach a waypoint with HERE SDK? - android

I'm using HERE android premium SDK.
App is generating a route with multiple waypoint, and start the navigation process.
I'm trying to find a way to detect each time a user has stop or pass through a route defined waypoint (defined as a stop point).
Is there a procedure for this?

You can use NavigationManager#ManeuverEventListener to listen for maneuver updates, then use the NavigationManager#getNextManeuver and NavigationManager#getAfterNextManeuver APIs to check the upcoming Maneuvers. Then, you can use Maneuver#getAction() API to check if the Action is STOPOVER.
API Docs:
NavigationManager
Maneuver

How I do/did it?
A combination of onStopoverReached(int index) and a dummy Passthrough as a Stopover.
Set your RoutePlan with the Passthrough waypoint and a dummy stopover waypoint of the same credentials as the Passthrough waypoint.
Call the NavigationEventManager's onStopoverReached method to tell you when the dummy Passthrough stopover has been reached or passed.
Other thing to note...
A ReRoute listener will never return a Passthrough Waypoint so...
You can use the reRouteEnd method to reinsert a Passthrough Waypoint in a new RoutePlan along with the Stopover Waypoints returned by reRouteEnd's RouteResult and recalculate a new route and of course pickup a fresh RouteResult at the Router listener's onCalculateRouteFinished.

Related

Making the location indicator in turn-by-turn navigation always look forward even when deviating from the route?

Is it possible to ensure that the location indicator doesn't keep pointing back to the route while you are deviating from it? It makes it very hard to see what's in front of the user as when camera tracking mode is turned on, it locks the camera to the location indicator's direction (e.g indicating to go back -> makes the camera look back),
What I want is to be able point the location indicator to wherever the user is going towards, so if they do a right turn and it just happens to deviate from the route, I want it to continue looking forward and not backwards to the route.
Figured it out.
Since I use a custom location provider, I have to create a custom "HERE Location" object, but there's a nice property in this object to set its bearings; "setBearingInDegrees", simply find the user's bearings and set it using this setter.
e.g:
var bearing = 0.0;
Location location = new Location.Builder()
.setCoordinates(geoCoordinates)
.setBearingInDegrees(bearing)
.build();
You would then set this 'location' back to the VisualNavigator so that it shows this location on the default indicator using its method 'onLocationUpdated'.
Even if you're on camera tracking mode, this will make you face the bearing you set in this location, which is perfect and exactly what I needed.
More information is found in the 'Add a Location Indicator' section:
https://developer.here.com/documentation/android-sdk-navigate/4.10.4.0/dev_guide/topics/map-items.html

How to get duration in HERE map android

I need a duration of the route. It would be great if we can get duration with include traffic and exclude traffic both.
We can get distance of a route, but I need duration of that route.
I assume you talk about the Premium HERE Mobile SDK ?
In a short:
1) Route calculation needs to happen with traffic request:
DynamicPenalty dp = new DynamicPenalty();
dp.setTrafficPenaltyMode(Route.TrafficPenaltyMode.OPTIMAL);
CoreRouter cr = new CoreRouter();
cr.setDynamicPenalty(dp);
See https://developer.here.com/documentation/android-premium/api_reference_java/com/here/android/mpa/routing/Route.TrafficPenaltyMode.html as reference.
2) When you get back a route object, it contains all information you want. You can query the data via getTtaIncludingTraffic or getTtaExcludingTraffic methods, see:
https://developer.here.com/documentation/android-premium/api_reference_java/com/here/android/mpa/routing/Route.html#getTta-com.here.android.mpa.routing.Route.TrafficPenaltyMode-int-
Additionally if you want to see more code, you can check out the HERE UI Components for the SDK here https://github.com/heremaps/msdkui-android where your usecase is also implemented (since it's open source you can have a look in the code how it's done there).

Reroute Here-map on destination change. It's a moving target

I am using Here Map Android SDK. Currently my app can calculate the initial route and draw it through NavigationManager. Listeners are implemented and it will recalculate/redraw when the position changes, but I have a moving target: the destination is another vehicle position I get from a web service at 30 second intervals.
What is the proper way to have the route adjusted for a change in destination?
The easy way is to create a new route with an updated destination waypoint, have it calculated, then replace the old route and its listeners with the new one. I fear this wastes computing resources and produces lag/flicker on the map during the redraw. If this is indeed the path to take, how do we minimize screen issues?
I tried just changing the coordinates of the waypoint but it has no impact. I searched for a "route waypoint change" listener, similar to a traffic or position listener but could not find any.
Update: Since Here confirmed a route destination cannot be updated, I clarify my request for "howto":
What objects can I reuse in the new one? Which objects must we remove from the map and/or destroy to avoid leaks?
Initial plan:
keep handle on waypoint, original route (missing any?)
modify the destination waypoint coordinates
create a new route and have it calculated
move the destination map marker to the new destination
add new route
remove the original route (I assume the beginning of the route is similar in most update cases, so we avoid "flicker")
Anything missing? Listeners handling?
Here SDK does not provide such feature as of today. You can not change existing route or update its target. If you have new destination point you should calculate new route.

HERE-Android Prem SDK NavigationManager.RerouteListener

Why is the NavigationManager.RerouteListener not always called when I deviate from the route?
If this method is still called out, is it necessary to install a new Route in NavigationManager?
NavigationManager.getInstance().setRoute(route)
or does it happen automatically?
I can not find a parameter indicating whether I am on the route. Is there such a parameter and how to call it?
HereMaps SDK has some calculations to call the reroute listener. Like, is the user approaching the destination in any way or going away from the destination.
I observed the listener is called every time I try to go away from the destination.
Distance to reroute depends on many parameters like route, transport mode, traffice etc.
NavigationManager doesn't need to be set with the new route.
But, if you are showing the route object on Map, then clear the old route and redraw the new route.

Add a layer of paths on whole map

I use here-map sdk. I have db file with 16500 ! paths (coordinates of a point). I need to draw all paths on the map, when user activate function "show additional paths". But i think, if i try to fetch big number of path and add all poplilynes object on here map, it will take a huge amount of time.
Help to find the optimal solution.
I would filter your data based on the visible viewport and disable this functionality where it doesn't make much sense (continental or globe level).
So, let's assume you app shows the map on zoomlevel 16 or 17 (district level), you can retrieve the viewport as GeoBoundingBox from the Map instance (e.g. via mapView.getMap()) with getBoundingBox().
The GeoBoundingBox makes it easy for you now to check for collisions with your own objects, since it has several "contains()" methods.
So everything that collides with your viewport should be shown, everything else is ignored.
You can update whenever the map viewport changes with either listening for OnTransformListener in the Map class or register for the MapGesture events (get MapGesture via getMapGesture() and listen for zooming events via addOnGestureListener())
If the amount of data for filtering is still too big, you can also think about preparing your data for more efficient filtering, like partitioning (region based would be my first idea) so only a subset of your data needs to be filtered.
It seems that Custom Location Extension (https://developer.here.com/platform-extensions/documentation/custom-location/topics/what-is.html) can help with this case.
In short, it allows you to upload a custom data to the HERE backend and query it later.

Categories

Resources