How to get remaining route/coordinates from current navigation route - android

Is there a way to get the remaining route or coordinates from the current navigation route while driving? I am using HERE SDK for Android (Premium Edition) 3.15. Example: If the whole route is 100% and I've driven 20%, I would like to get the remaining 80% of the route/coordinates.
PS: If I can get the next waypoint that I need to pass through would also be helpful.

VenueNavigationManager and FTCRNavigationManager(in beta) provides methods that can get the distance travelled, also the method that returns the remaining time and distance. Including the API references for the premium Android Edition :
https://developer.here.com/documentation/android-premium/3.16/api_reference_java/index.html?com%2Fhere%2Fandroid%2Fmpa%2Fvenues3d%2FVenueNavigationManager.html
&
https://developer.here.com/documentation/android-premium/3.16/api_reference_java/index.html?com%2Fhere%2Fandroid%2Fmpa%2Fftcr%2FFTCRNavigationManager.html

Related

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).

How to filter markers in Mapbox Sdk

I'm creating an Android app using MapBox. I've already set up a simple map functionality with markers sourced from .json file. Next step is filtering the markers on the map, just like in this gl-js example here:
https://docs.mapbox.com/mapbox-gl-js/example/filter-markers/
I can't find any sdk examples anywhere, and since this is my first app I really can't figure it out on my own. Any help will be appreciated.
You can check out this example https://docs.mapbox.com/android/maps/examples/multiple-expressions-temperature-change/ that features two layers that fetch a min or max temperature from the data source and display it.
The filtering part is done here:
// Only display Maximum Temperature in this layer
maxTempLayer.setFilter(eq(get("element"), literal("All-Time Maximum Temperature")));
loadedMapStyle.addLayer(maxTempLayer);
Filters accept expressions as arguments, and here Expression.eq is used to compare "element" from the GeoJSON data source (referenced with the Expression.get) with the "All-Time Maximum Temperature" value. If it resolves to true, the feature is going to be displayed, otherwise, it's going to be hidden.

Displaying KML Layers on Maps at Native Android apps Best Practice

I have big KML file to a native Android application, please check the following details and give an advice.
KML file details:
size: 1.7 MB
total number of kml file elements: 500 elements
total number of polygon: 1000 polygon
Android app details:
the above details will be viewed in Fragment
I used the following support library to implement this screen
compile 'com.google.maps.android:android-maps-utils:0.4+'
some caluctations are done on loading the screens(like distance calculations)
Issue:
Take a lot of time to load the map and kml layer about 8 sec
create KMLLayer instance
What is the best practice to implement the above details with good performance?
please advise.
Best practice is doing long time operation in background (for example, on separate thread) and split complex tasks into small parts. So you can:
1) create and start load KML layer as soon as possible (e.g. on app create) and than just show it;
2) instead of one kml file with 500 elements and 1000 polygons, use 50 kml files with 10 elements and 100 polygons and load to layer only necessary files (for example you can split it by area location, or by semantic information, or by something else criteria);
3) combine 1 and 2 points;
4) precisely for google maps it's possible to create tiles with information from kml files and use TileProvider.
Since there's no actual answer, I'll post my own solution.
I've done mainly two things to optimize this.
Instead of using Google maps utils built-in method addLayerToMap - I've used my own custom implementation. I've done so, because parsing kml is relatively fast(in my case - ~5-10 seconds) and it can be done in background thread. Adding all the points to the map, however, takes more than 10 seconds, and must be done on UI thread. Basically, I've used KmlLayer class as a base, and parsed kml file by myself into polygonOptions and all other things I need.
Calculate which items are visible and which are not. Firstly, I filter which items are outside screen bounds. After that, I calculate each item's size(in pixels, no meters) - if item is smaller than threshold - item is also filtered out.
With these hacks applied, instead of freezing app for 15 seconds, user can freely navigate through map, and when he stops, after several seconds information will be displayed.
I just make some updates on the screen behavior to get good performance and good user experience by the following steps:
Divide the KML File to 65 files (the main areas on the map, for example, Zone A11 is located in one KML file and it contains all its details like Zone A11-1, Zone A11-2 and Zone A11-4 ...) and this division is done to be suitable the screen experience (for example user requirements)
on the first load, I am loading only the markers for all KMLs centers and that is not affecting the performance
When user click on the marker, I am loading the KML file for this area and zoom this area
When user zoom out, I am removing this layer from the map and load marker
When user moves the map I am calculating the nearest marker and load its KML layer
Note: preparing files on app launching will not provide better performance because the bad performance comes from adding the KML layer to the google map
Note2: using custom implementation for parsing and adding to Google map take a lot of time or need a lot of unit testing, and I think it's not recommended solution because it's better to leave this solution to be on Google Map utils build-in method (it's customized and always up to date)
I'd suggest you to make sure that you are constructing the KmlLayer on a background thread and addLayerToMap() has to be done on the main thread though like this
GlobalScope.launch {
val stringUrl: String = "https://saltwx.com/bath/SW_bath6.kml"
val inputStream: InputStream = URL(stringUrl).openStream()
val layer = KmlLayer(map,inputStream, applicationContext)
runOnUiThread {
try {
layer.addLayerToMap()
} catch (e: Exception) {
e.printStackTrace()
}
}}

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.

Google direction and voice navigation

I have been working on a android project.
Then I came up with 2 question.
Q1. how to implement navigation drive ?
My logic and some work
- I am be able to draw path between 2 address. And my thought is that, use the onLocationChanged(current) method then call https://maps.googleapis.com/maps/api/directions/output?parameters with the current location and destination which through some method to draw the path on the map.
Upon every onLocationChanged() method call, I redraw the path on the map again.
" Is it how we would do it for navigation ? "
Q2. how to implement voice navigation to work with Q1 ?
- Did some research, can't find anything that seems clearly helpful. All I know its that, in the return JSON from the /api/directions, there are direction instruction in it.
" Do I use it for voice from the return JSON ? Or there is a better way ? "
Would be very helpful with some link or example in details.
Thanks in adavnce
Here is what I know, hope it helps you out.
Regarding the first question:
After retrieving the directions and the necessary data, you have to draw the direction once and only once! yes, you have to use the onLocationChanged() but not to redraw the whole thing again.. if you notice in most of the navigation application they still keep the main route, they don't remove the passed parts... but you have to use onLocationChanged() to check if the user is out of the drawn path (by maybe 100m) so you have to re-calculate and redraw it again... redraw the path every time the user move is a costly operation it is better to be avoided...
For the second question:
As you said, the data retrieved already has the navigation commands.. so what you have to do is create a class to map the command with the voice.. and if you notice within the legs -> steps tags, there is a start and ending coordinates for each sub-path, so you can use these data to calculate the distance between them on each 200m say the command that "how far the user is to turn left" for example.
Hope this gives you a general idea of how it works. Good luck and happy programming.

Categories

Resources