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.
Related
We're displaying a number of map markers on the map representing various objects which are retrieved either from a cache or from an asynchronous network call. When these objects are retrieved, we update the camera to ensure all markers are within view:
LatLngBounds bounds = mBoundsBuilder.build();
mMapboxMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50, 100, 50, 30));
We're interested in adding the user's location to the map, and have done so using the LocationComponent provided by MapBox as shown in this example.
The problem is that when the LocationComponent has locationComponent .setCameraMode(CameraMode.TRACKING) set as shown, the camera will focus on the user's location, without accommodating the markers previously set. Setting the camera mode to CameraMode.NONE allows the markers to be shown using the code snippet above, however in this case the user's location will not be accommodated in the mBoundsBuilder.
The obvious solution seemed to be to listen for location updates and manually add the coordinates to the mBoundsBuilder so that the user's location is taken into account. This, however, has a number of problems, such as:
Callbacks for location changes can be invoked many times, while the mBoundsBuilder should only contain a single set of coordinates for the user's location, the rest of the objects being the previously added markers.
Location updates are asynchronous, and getLastKnownLocation will often return null.
Questions:
Is there a default, built in way to show a user's location while making sure the camera accommodates map markers?
If no default option exists, how can this be properly implemented?
Version:
com.mapbox.mapboxsdk:mapbox-android-sdk:6.8.1
Take a look at this -> https://www.github.com/bkhezry/MapDrawingTools it helps in drawing polygons on a map.
Mapbox provides good Navigation SDK for Android, and what I have been trying to do is pass custom lat and lng's to mapbox navigation launcher. But its taking current user location and i would like to pass the custom coordinates . Is that possible?
You need to build a DirectionsRoute and then eventually give it to the NavigationLauncherOptions.Builder.
You can build a route with a custom origin instead of the device location.
Also, you can add custom waypoints.
Create a waypoint via the Point class. Point wayPoint = Point.fromLngLat(longCoordinate, latCoordinate);
Once you get the route from the response, you can eventually give it to the options builder before starting the NavigationLauncher.
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.
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.
I have mapped my current location and also 4 other locations on my map.Is it possible the mark the route which is closest to the current location(1),then from that(1) to the next closest(2) position,then so on(3).!!Finally i should have the route from my current location marker via all the location in between(markers) till the last marker!!
Thanks in advance!!
You are going to have to use separate instance of DirectionsService object to make your directions request for each destination and then set that to the map using the same instance of the DirectionsRenderer object.
Take a look at this JSFiddle
There are three separate directions in this example. Just make the start the same location.