How to get duration in HERE map android - 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).

Related

How to get remaining route/coordinates from current navigation route

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

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.

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.

How to get programmatically the data usage limit set by user on Android OS configuration?

User can define at Data Usage screen a limite and/or a warning limit for mobile data usage. So how can I get this information by code?
Screen of Data Usage configuration of native OS.
I wanna the limit value and warning value.
I've already tried this but not work and always return NULL to both:
final Long recommendedBytes = DownloadManager.getRecommendedMaxBytesOverMobile( this.context );
final Long maximumBytes = DownloadManager.getMaxBytesOverMobile( this.context );
// recommendedBytes and maximumBytes are NULL
And TrafficStats class just have a data transferred not the limits.
After days searching and research about this problem I couldn't find a answer for that. Bellow I will lift every attempt that I did.
1. Download Manager
With this class you can start download over any network or device
state and it will handle all states e.g. network loss, device reboot,
etc...
There are two methods called getMaxBytesOverMobile and
getRecommendedMaxBytesOverMobile, they was a pretty candidate
to solve this problem at first time. But after code tests and
Download Manager implementantion research I'd found that there is
no way to get thoose values by DownloadManager.
Reason
Thoose methods call Settings.Secure.getLong with they
respective labels
Settings.Secure.DOWNLOAD_MAX_BYTES_OVER_MOBILE and
Settings.Secure.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE in
the turn makes a call to a lazy String map inside inside a
inner class called NameValueCache.
Ok so far but none of inner classes or Settings implementation it
self use DOWNLOAD_MAX_BYTES_OVER_MOBILE or
DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE inside.
I considered the lazy map was populate by a third entity, what
actually happens, so I found the NameValueTable Settings
inner class that handle the new values to lazy map. The
putString is a protected method call by Settings.Secure
and Settings.System inner classes (calls of Secure and
System).
So I could conclude that if the OS implementantion do not put thoose String values I can't get them.
2. TrafficStats
Just a quick look on official reference I could notice that it will
not help me because this class just provide the amount of bytes and
packages that was trafficked since last device boot.
http://developer.android.com/reference/android/net/TrafficStats.html
3. NetworkPolicyManager and NetworkPolicy
As #bina posted here the both classes are hidden and could not
be use by normal apps e.g. that will be published in Google Play.
https://stackoverflow.com/a/24445424/575643
4. ConnectivityManager
In short, you just can get the NetworkInfo that not provide
much information about user preferences (really none!). Just provide
informations about network and e.g. mobile network provider.
http://developer.android.com/reference/android/net/ConnectivityManager.html
After all I assume that no way to get this information nowadays. Please if you read it and found a way post here!
Thanks for all.
PS.: Sorry by english mistakes.
Do you want to get limit value(5GB) and warnning value(2GB) in this example?
If so, you can get limitBytes and warningBytes by the following code, if you can use android.permission.MANAGE_NETWORK_POLICY and android.permission.READ_PHONE_STATE.
However, android.permission.MANAGE_NETWORK_POLICY protectionLevel is signature.
NetworkPolicyManager manager = (NetworkPolicyManager) getSystemService("netpolicy");
NetworkPolicy[] networkPolicies = manager.getNetworkPolicies();
Log.d("NetworkPolicy", "limitBytes is " + networkPolicies[0].limitBytes);
Log.d("NetworkPolicy", "warningBytes is " + networkPolicies[0].warningBytes);
(NetworkPolicyManager and NetworkPolicy classes are hidden)

Categories

Resources