Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a route avoiding some locations #277

Closed
113408 opened this issue Jun 9, 2018 · 1 comment
Closed

Generate a route avoiding some locations #277

113408 opened this issue Jun 9, 2018 · 1 comment

Comments

@113408
Copy link

113408 commented Jun 9, 2018

Hi Mapbox Team! I have been using Mapbox for my app to generate route and turn-by-turn navigation and it's working well. However I would like to avoid to go through some coordinates of the route but I can't figure it out.

The code to get the route :

Directions.shared.calculate(options) { [unowned self] (waypoints, routes, error) in
    // Take first route and customize it in a way to get around some coordinates
}

Here is a scenario :

1- User location is latitude = 37.332331410000002, longitude = -122.0312186

2- The user is going to Santa Clara Unified School located on latitude = 37.354100000000003,longitude = -121.9552

3- The Api generates the following route :

[0] = {
latitude = 37.332329999999999
longitude = -122.03118000000001
}
 [1] = {
   latitude = 37.332619999999999
   longitude = -122.03118000000001
 }
 [2] = {
   latitude = 37.332609999999995
   longitude = -122.03097000000001
 }
 [3] = {
   latitude = 37.332609999999995
   longitude = -122.03076000000001
 }
 [4] = {
   latitude = 37.332199999999993
   longitude = -122.03076000000001
 }
 [5] = {
   latitude = 37.331689999999995
   longitude = -122.03076000000001
 }
 [6] = {
   latitude = 37.331689999999995
   longitude = -122.03190000000002
 }
 [7] = {
   latitude = 37.331719999999997
   longitude = -122.03199000000002
 }
 [8] = {
   latitude = 37.331759999999996
   longitude = -122.03205000000003
 } ...

4- Suppose the generated route goes through East Homestead Rd, I would like to be able to avoid this road and generate a new route even if it's a longer one.In the screen below avoid the route in red because going through East Homestead Rd and take the next fastest route not going through East Homestead Rd enter image description here
screencapture

Any help would be appreciated !

@1ec5
Copy link
Contributor

1ec5 commented Dec 28, 2019

The Directions API doesn’t currently support avoiding specific areas, only certain road types.

As a workaround, perhaps you could write heuristics for this purpose. If you see that the route comes within some distance of the location you want to avoid (by calling LineString.closestCoordinate(to:) and checking the return value’s distance), you could recalculate the route, this time passing an alternative location as a via point (setting separatesLegs to false on the waypoint).

This is at best a limited workaround, but since there’s no underlying support in the Directions API for the actual feature you’re requesting, I’m closing this issue until things change.

@1ec5 1ec5 closed this as completed Dec 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants