I want to make a navigation application on Android (Kotlin) using the mapbox-android SDK. I need to create a route with specific waypoints and want to know when I am near one of those waypoints (200m before for example). I already managed to display a map with my waypoints with the NavigationRoute object and launch a turn-by-turn navigation using the NavigationLauncher object. Still, I don't have a clue how to know when I'm getting near a waypoint. I've read things about milestones event listener (step or route), RouteProgress (leg or route), but I don't know if it's the right approach to do this.
I tried to declare a milestone with a STEP_DISTANCE_REMAINING_METERS and add a MilestoneEventListener but nothing fire up in my logs. Like I said, I don't even know if it's the right way to do this.
val milestone = RouteMilestone.Builder()
.setIdentifier(100)
.setTrigger(Trigger.all(
Trigger.lt(TriggerProperty.STEP_DISTANCE_REMAINING_METERS, 200)
))
.build()
navigation = MapboxNavigation(this#MainActivity, Mapbox.getAccessToken())
navigation.addMilestone(milestone)
navigation.addMilestoneEventListener { _, _, milestone ->
Log.d(TAG, "milestone triggered: " + milestone.instruction)
}
navigationMapRoute = NavigationMapRoute(navigation, mapView, map, R.style.NavigationMapRoute)
navigationMapRoute!!.addRoute(currentRoute)
I'm using those versions of mapbox SDK
mapbox-android-sdk:5.3.2
mapbox-android-navigation:0.9.0
mapbox-android-navigation-ui:0.9.0
If you know the location of your waypoints you could just use Location Manager's Proximity Alert
Related
I am using here maps android sdk premium version for map navigation in my android app.
I have successfully implemented here maps navigation. While navigating, if I go out of route then reroute calculation occurs and new route to given destination is shown but if I go through a restricted road, then here maps only says rerouting which is true since from restricted road it cannot calculate the route.
But is there any way I can show nearest exit from the restricted road to get a new route to destination on here maps android? Right now, on the restricted roads, no route is shown.
#Override
public void onRouteUpdated(#NonNull Route route) {
Log.d(TAG, "onRouteUpdated: called.");
//remake new route
map.removeMapObject(mapRoute);
// create a new MapRoute object
mapRoute = new MapRoute(route);
// display new route on the map
map.addMapObject(mapRoute);
}
The above code is not useful while on restricted road. Tried using listener as:
private NavigationManager.RerouteListener rerouteListener = new NavigationManager.RerouteListener() {
#Override
public void onRerouteBegin() {
super.onRerouteBegin();
Toast.makeText(activity, "reRouteListener begin...", Toast.LENGTH_SHORT).show();
}
#Override
public void onRerouteEnd(#NonNull RouteResult routeResult, RoutingError routingError) {
super.onRerouteEnd(routeResult, routingError);
StringBuilder stringBuilder = new StringBuilder();
for (RouteResult.ViolatedOption violatedOption: routeResult.getViolatedOptions()) {
stringBuilder.append(violatedOption.toString());
}
Toast.makeText(activity, "routeresult end: " + stringBuilder, Toast.LENGTH_SHORT).show();
}
};
Sometimes got violated options as START_DIRECTION and sometimes nothing. But still stuck on how to achieve nearest route as such on restricted road.
[update] :
I tried suggestion from #Datasun. But I got invalid routing on initiating new route from restricted road (tried from height restricted road). My problem is while navigating, if user goes to restricted road, the route disappears and it says route recalculating. I want to show user nearest exit from the restricted road or some notification that they are on restricted road. Right now I'm getting violated options of START_DIRECTION but sometimes nothing on the restricted road. What am I missing?
To summarize, within the Navigate SDK the issue is not reproducable any more.
In general the HERE Premium SDK (3.x) is superseded by new 4.x SDK variants and the Premium SDK will be maintained until 31 December 2022 with only critical bug fixes and no feature development / enhancements.
Current users of the HERE Premium SDK (3.x) are encouraged to migrate to Lite, Explore or Navigate HERE SDK (4.x) variants based on licensed use cases before 31 December 2022. Most of the Premium SDK features are already available in the new SDK variants.
I am integrated new place API and I am using the below method to get the nearest place list.
private fun getNearestPlaceList(placesClient: PlacesClient) {
val placeFields = listOf(Place.Field.NAME, Place.Field.ID, Place.Field.LAT_LNG)
val request = FindCurrentPlaceRequest.builder(placeFields).build()
placesClient.findCurrentPlace(request).addOnSuccessListener { response ->
placeList.clear()
response.placeLikelihoods.map { placeLikelihood -> placeLikelihood.place }
.filter { place -> !place.id.isNullOrEmpty() && !place.name.isNullOrEmpty() }
.forEach { place ->
val placeModel = PlaceModel(place.name!!, place.id!!)
placeList.add(placeModel)
}
setAdapter(placeList)
}.addOnFailureListener { exception ->
if (exception is ApiException) {
Log.e(TAG, "Place not found: " + exception.statusCode)
}
}
}
The current API is only collecting the nearest location of my device current location. But My requirement is to get the nearest place of a Specific(Different) location. So Is it possible to input location info(Different Lat Long) to the API and get the nearest list of that location?. Currently, the API is automatically collecting the current location and it's sending a list of nearest places. Anyone have a solution, please update?
Getting the nearest places from a specific location (not the device's current location) is not currently available in the Places SDK. To clarify, the PlaceLikelihood's from the FindCurrentPlaceResponse are places where the device is likely to be located.
The FindCurrentPlaceResponse contains a list of PlaceLikelihood
objects representing places where the device is likely to be located.
For each place, the result includes an indication of the likelihood
that the place is the right one. The list may be empty, if there is no
known place corresponding to the given device location.
As I understand your use-case, you can get a list of nearby places for a specific location through Places API - Nearby Search.
A Nearby Search lets you search for places within a specified area.
You can refine your search request by supplying keywords or specifying
the type of place you are searching for.
Sample request:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=1500&type=restaurant&keyword=cruise&key=YOUR_API_KEY
There are also available open source client libraries that you can use for Google Maps Web Services. More info here.
Lastly, there is also an existing feature request for this in Google's Public Issue Tracker. I'd recommend you "star" it to receive updates.
https://issuetracker.google.com/issues/133276015
Hope this helps!
I am using HERE Android SDK to perform turn by turn navigation project. But I do not get the result similar to image.
I hava this code to get the current manauver
private NavigationManager.NewInstructionEventListener newInstructionEventListener = new NavigationManager.NewInstructionEventListener() {
#Override
public void onNewInstructionEvent() {
Maneuver maneuver = navigationManager.getNextManeuver();
if (maneuver != null) {
if (maneuver.getAction() == Maneuver.Action.END) {
}
tvManeuver.setText(navigationManager.getNextManeuver().getTurn().name() + " " + maneuver.getIcon().value());
ivTitle.setImageBitmap(maneuver.getNextRoadImage().getBitmap());
tvStreet.setText(maneuver.getRoadName());
tvMeters.setText("durante " + maneuver.getDistanceFromPreviousManeuver() + " m");
if (maneuver.getDistanceToNextManeuver() == 0) {
tvMeters.setVisibility(View.GONE);
} else {
tvMeters.setVisibility(View.VISIBLE);
}
}
}
};
But I do not get the correct text of the maneuver. For example "Turn right at the next corner" and the and the corresponding arrow icon to put inside IMAGEVIEW.
can anybody help me?
Regards.
I assume the image you provided is from HERE Maps available on Google Store which is a custom implementation using the HERE SDK.
The instruction you can get from Maneuver , check documentation
https://developer.here.com/mobile-sdks/documentation/android-hybrid-plus/topics_api_nlp_hybrid_plus/com-here-android-mpa-routing-maneuver.html#topic-apiref__getinstruction-void
Icon should also be retrieved from getIcon() , which gives an enumeration and you will need to create images for possible enumerations in the icon , check documentation
https://developer.here.com/mobile-sdks/documentation/android-hybrid-plus/topics_api_nlp_hybrid_plus/com-here-android-mpa-routing-maneuver-icon.html#topic-apiref
If you want to get the list of maneuvers, you can't get it on the NewInstructionEvent.
Since you are already in navigation you should already have your route object. On the route object you can just call getManeuvers(). That will give you all the list of maneuvers for the current route.
You can also refer to their UI Kit https://developer.here.com/blog/build-beautiful-interfaces-with-the-here-mobile-sdk-ui-kit-for-android-and-ios.
Hope this helps. I know this is an older thread.
HERE SDK Premium does not provide Maneuver Instructions pre- start of Navigation nor can you get a list of Maneuver Instructions at any point.
You however could get a list of Maneuver Instructions using the HERE Routing API.
https://developer.here.com/documentation/routing-api/dev_guide/topics/use-cases/actions.html
One more way is to get Instructions through the AudioPlayerDelegate.PlayText callback.
I am creating an app where I need to start the navigation app and then use the result (most importantly the driven distance). I am starting the navigation activity with startActivityForResult and using the scheme "google.navigation". Like this:
Intent i = new Intent(
Intent.ACTION_VIEW,
Uri.parse("google.navigation:q=Somewhere"));
startActivityForResult(i,1);
This works great, I get a callback when the activity is done, but the data portion of the activity is empty.
Is there a way to do this?
Is there a navigation history where I can browse the latest trip for data?
Best Regards
Jakob Simon-Gaarde
Is there a way to do this?
No, there is no way for you to force an activity to give you a result. The determination of whether an activity supports a result lies in the authors of the activity, not the caller of the activity.
Is there a navigation history where I can browse the latest trip for data?
There is no documented and supported API for the Google Navigation Android app (which includes the google.navigation scheme).
I don't know about callbacks from Google Navigation. But if you are only interested in getting the driven distance, you could keep listening to the location updates in the background and calculate the distance yourself. The following function uses android.location.Location to calculate distance between two LatLang coordinates:
public double getGeodesicDistance(LatLng from, LatLng to){
Location _fromLoc = new Location("From location");
_fromLoc.setLatitude(from.latitude);
_fromLoc.setLongitude(from.longitude);
Location _toLoc = new Location("To location");
_toLoc.setLatitude(to.latitude);
_toLoc.setLongitude(to.longitude);
return Math.round(_fromLoc.distanceTo(_toLoc)); // distance in metres
}
But if you decide to take this approach, you should detect the sudden jumps in GPS data and handle them accordingly.
You could get the location right before you start the navigation, and get it again once the navigation is closed, and calculate the difference.
I am new to android and developing a navigation based application for android.My question is I want to show a route with multiple way-points between source and destination node in Google maps and I don't know how to do it. I have search for this but most of the results are for two points.
Please help me to solve my problem
e.g:- when app user submits the destination with some way-points the map should display the route from the source to destination with those way-points on the phone.
Thanks !
I don't think the Maps intent offers those capabilities, but you do have some other options
Better but more work
1)Create your own map activity that displays routes for multi-location(using a mapview and overlays). Here is an example of how to convert the kml file to a route
Quicker and Easier
2)Create a simple webview (or you can just intent a new one with a given url) and dynamically build the url for a google maps api request with waypoints. See Google's website for documentation on getting a map with routes via waypoints.
"I have search for this but most of the results are for two points." You already found everything you need to do this.
For this, you're not "drawing through the waypoints along the way," you're actually going to have to draw a route between 2 points for each waypoint you have:
IE. You want to get from point A to point D, and on the way there are points B and C. The solution is to draw a route from A to B, B to C, and finally C to D.
You can use the map intent like this:
String address = "http://maps.google.com/maps?daddr=" + "Latitude" + "," + "Longitude" + "+to:" +"Latitude" + "," + "Longitude";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(address));
startActivity(intent);
in this case the start point will be your current location and you can add as many intermediate points as you want using "+to:"