I am drawing navigation routes with via points. I want navigation should follow exactly the same route as via points provided. To achieve this what type of Route Mode should i set?
Right now i am setting SKRouteMode.EFFICIENT, but somehow route drawn is different many times.
I dont want any fastest or shortest route but the route which exactly follow my via points.
Please help(I am using SDK 2.5)
Following are the coordinates:
Start Point: -104.98036489999998,39.7435209
End Point: -104.98036489999998,39.7435209
Via Point:
-104.97252523899078,39.74324265487236
-104.96009051799774,39.74316428375109
-104.95895862579346,39.74350251637351
-104.95895862579346,39.74350251637351
-104.94109511375427,39.74377062667071
-104.94064809999998,39.707593
-104.94056940078735,39.71219659344454
-104.94062304496765,39.73016169331405
-104.94062036275864,39.73711087652619
-104.94078397750854,39.74018611509486
-104.9781499,39.7401722
-104.99110221862793,39.74328802758604
-104.99050829999999,39.7428701
-104.98829126358032,39.74547413202817
-104.99693870544434,39.75225473927719
-105.00033380000002,39.7506546
-104.9958872795105,39.754481800432515
-104.99119210000003,39.7543157
-104.98791575431824,39.751256662580026
-104.98734712600708,39.75011009381583
-104.98737931251526,39.74344476945796
-104.98623132705688,39.74330865153693
Here is the configuration:
prefSpeedInTown- 0
prefSpeedOutTown- 0
tollRoads- false
avoidFerries- false
highWays- false
Route Mode: RouteMode.EFFICIENT
Related
So Mapbox provides an awesome Navigation SDK for Android, and what I have been trying to do is create my own routes, representing each point as a Feature in a Geojson file, and then passing them on to the MapMatching module to get directions that I can then pass to the Navigation Engine.
My solution evolves into two main parts. The first one involves iterating through the points I want navigation to go through, by adding them as input to the .coordinates element of MapboxMapMatching.builder() and subsequently converting this to
.toDirectionRoute(); per Mapbox instructions and example here: https://www.mapbox.com/android-docs/java/examples/use-map-matching/
private void getWaypointRoute(List<Point> features) {
originPosition = features.get(0);
destinationPosition = features.get(features.size() - 1);
MapboxMapMatching.builder()
.accessToken(Mapbox.getAccessToken())
.coordinates(features)
.steps(true) // Setting this will determine whether to return steps and turn-by-turn instructions.
.voiceInstructions(true)
.bannerInstructions(true)
.profile(DirectionsCriteria.PROFILE_DRIVING)
.build().enqueueCall(new Callback<MapMatchingResponse>() {
#Override
public void onResponse(Call<MapMatchingResponse> call, Response<MapMatchingResponse> response) {
if (response.body() == null) {
Log.e(TAG, "Map matching has failed.");
return;
}
if (response.isSuccessful()) {
currentRoute = response.body().matchings().get(0).toDirectionRoute();
The second bit involves just passing 'currentRoute' to the NavigationLauncher as shown below:
NavigationLauncherOptions options = NavigationLauncherOptions.builder()
.origin(origin)
.destination(destination)
.directionsRoute(currentRoute)
.shouldSimulateRoute(simulateRoute)
.enableOffRouteDetection(false)
.build();
// Call this method with Context from within an Activity
NavigationLauncher.startNavigation(MainActivity.this, options);
An example of the route can be seen here Android Simulator Snapshot with Route . Each point across the route, is an intersection, and corresponds to a feature in my GeoJson file. The problem becomes when I launch the navigation. Every time, either in the simulator or on a real device, each point is interpreted as a destination so the voice command goes 'You have reached your first (second, third etc) destination'. I find this annoying as I would like to have a single route with a destination and that's it. I would just like to have this points so I have my own custom path, instead of the shortest path typically returned by routing applications. I try to avoid the problem by setting voiceInstructions off but then the system goes bananans and the navigation screen moves to lat, lng (0,0) which is pretty much somewhere West of Africa. Any help on how I could resolve this it would be greatly appreciated and I would be happy to buy a beer or two for the person that provides the right answer. I have reached out to Mapbox Support as well but we have not found an answer to the problem so I asked them to escalate it internally within their engineering team, as I believe, although the problem I am solving is not uncommon, it is still not very much tested by developers. Cheers!
So here I am and after the kind support of Mapbox Support and Rafa Gutierrez
I can now answer this post myself.
The problem has been arising due to MapboxMapMatching automatically setting .coordinates as waypoints. If instead, one edits explicitly the waypoints variable to have only two waypoints: origin and destination, then the system is able to process the input customised route without translating each input coordinate as a waypoint. The code example below hopefully clarifies the point described above:
MapboxMapMatching.builder()
.accessToken(Mapbox.getAccessToken())
.coordinates(lineStringRep.coordinates())
.waypoints(OD)
.steps(true)
.voiceInstructions(true)
.bannerInstructions(true)
.profile(DirectionsCriteria.PROFILE_DRIVING)
.build().enqueueCall(new Callback<MapMatchingResponse>()
where OD is an array of integers storing the first (origin) and last index (destination) of your coordinates
OD[0] = 0;
OD[1] = features.size() - 1;
is it possible to follow a path on google map android (Programmatically) if my android device getting away from the path it notify or show alert that your not following your path
Help will be appriciated,
Thank's :)
Yes, it's possible by several ways. For example you can use PolyUtil.isLocationOnPath(LatLng point, java.util.List<LatLng> polyline, boolean geodesic, double tolerance) from Google Maps Android API Utility Library. In this case you need to check (with isLocationOnPath()) if user location laying on segment of the polyline of your path. Something like that:
if (!PolyUtil.isLocationOnPath(userLocationPoint, pathPolyline.getPoints(), true, 50)) {
// user away of pathPolyline more than 50 meters
// show your alert here
...
}
}
where 50 - is tolerance (in meters).
NB! It's not a complete solution - just approach.
Also you can use geofence monitoring for several waypoints (with a limit of 100 per device user).
I need to get many points of simulated route. My goal is get all points to paint a route using shape with SKPolyline in another view. How can I get that?
Regards.
If i understand your goal you want to draw the route that skobbler calculate for you using SKPolyline.
After request route calculation the callback onRouteCalculationCompleted will call with SKRouteInfo.
To get the route positions try:
List<SKExtendedRoutePosition> list = SKRouteManager.getInstance().getExtendedRoutePointsForRoute(skRouteInfo.getRouteID());
Don't forget to set ExtendedPointsReturned=true when you request route calculation.
SKRouteSettings routeS = new SKRouteSettings();
routeS.setStartCoordinate(startPosition.getCoordinate());
routeS.setDestinationCoordinate(destinationPosition.getCoordinate());
// number of alternative routes specified here
routeS.setNoOfRoutes(1);
routeS.setRouteMode(SKRouteSettings.SKRouteMode.CAR_FASTEST);
//set true if you want the route is draw on map
routeS.setRouteExposed();
routeS.setExtendedPointsReturned(true);
SKRouteManager.getInstance().calculateRoute(routeS);
etzuk's answer is correct, but remember to cached the route before you can get all the skPosition of created route.
On onRouteCalculationCompleted, add saveRouteToCahce before getting route's coordinates like this:
SKRouteManager.getInstance().saveRouteToCache(skRouteInfo.getRouteID());
List<SKExtendedRoutePosition> coordinatesForRoute = SKRouteManager.getInstance()
.getExtendedRoutePointsForRoute(
skRouteInfo.getRouteID());
I have an example route that I've tested using the Skobbler SDK.
Start Point: around 820 S MacArthur Blvd
Irving, TX 75063
End Point: Bass Performance Hall, Fort Worth, TX
Via Point #1: Shell Gas Station, 1224 Oakland Blvd Fort Worth, TX
The code that's used to calculate the route is as follows:
SKRouteSettings route = new SKRouteSettings();
// set start and destination points
route.setStartCoordinate(start);
route.setDestinationCoordinate(end);
route.setNoOfRoutes(1);
// set the route mode
route.setRouteMode(SKRouteSettings.SKRouteMode.CAR_FASTEST);
// Traffic enabled
route.setUseLiveTraffic(true);
route.setUseLiveTrafficETA(true);
route.setTollRoadsAvoided(true);
route.setAvoidFerries(true);
route.setHighWaysAvoided(true);
ArrayList<SKViaPoint> viaPoints = new ArrayList<SKViaPoint>();
viaPoints.add(new SKViaPoint(VIA_POINT_ID_OTW_DEST, viaPoint));
route.setViaPoints(viaPoints);
// set whether the route should be shown on the map after it's computed
route.setRouteExposed(true);
// Set traffic routing mode
SKRouteManager.getInstance().setTrafficRoutingMode(SKMapSettings.SKTrafficMode.FLOW_AND_INCIDENTS);
// set the route listener to be notified of route calculation
// events
SKRouteManager.getInstance().setRouteListener(this);
// pass the route to the calculation routine
SKRouteManager.getInstance().calculateRoute(route);
When I compute this route via the Skobbler SDK and display the calculated route on the SKMapView, I sometimes get a route that doesn't make sense.
This route calculated on one of our test devices shows the calculated route taking us off the freeway, turning right onto a street and then making a u-turn at the end of the street, before turning right again into the Shell gas station. For some reason, the routing algorithm is not realizing that the route can go straight off the freeway and then turn right, or alternatively, turn right at the street off the freeway and then make an immediate left.
This is not the only instance of incorrect routing that we have witnessed, but it is the most recent. In the past, we have been able to make slight modifications to the coordinate passed for the via point to make the routing algorithm return a sensible route, and then were able to go back to recalculating the original route correctly without the long detours.
In this case, in order to view the corrected route below, we simply try routing the same route again some time later:
Has anyone experienced an issue similar to this and is there something that can be done on the client side to prevent it? Or perhaps a request setting that can be made while requesting a route calculation to the server that might help?
Thanks for any feedback on the matter!
-Keith
I'm need to use GoogleMaps for an android app
I need to build an android app that sends request to GoogleMaps API and recive only the list of directions (Turn right in 400meters at the next..) without showing any map
How to I update the list by user movement ?
(You currently passed first turn, heading to second turn.. 800 meters to next turn.. 400 meters to next turn)
If in answer 2 I get only String with "Left,Right,North.." How do I get the turn angle ?
(45-125 will be right, 90 will be absolute right)
I would like to hear about how to optimize the update ( There are 4 ways to use threads in android so I've heard )
Listen for Location Updates using requestLocationUpdates().
http://developer.android.com/training/location/receive-location-updates.html#StartUpdates