问题
I want to avoid some coordinates while using directions APIs.I have read the below blog https://code.google.com/p/gmaps-api-issues/issues/detail?id=214
Which ensures that Directions API doesn't allow if I want to avoid specific coordinate.
Then I have tried with waypoint parameter (Which allow us to get routes that include specific coordinate) with considering same source and destination:
1) First get the routes without adding waypoint
https://maps.googleapis.com/maps/api/directions/json?origin=25.2958001,55.436142&destination=24.914744,54.968565&alternatives=true&mode=driving&key=MYKEY
2) Get the routes by adding waypoint (Coordinate which I want to avoid)
https://maps.googleapis.com/maps/api/directions/json?origin=25.2958001,55.436142&destination=24.914744,54.968565&waypoints=25.244456,55.404643&alternatives=true&mode=driving&key=MYKEY
3) Then compare results and try to remove routes from 1st step which consists by 2nd step.
But in this case, 1st step returns multiple result which passing from the same coordinate (which I want to avoid) and that results are not included by the 2nd step.
I'm fed up with this. And I need to solve this anyhow.
Anyone can help me with this? Or Some other suggestions or calculation which can help me with stuff?
Thanks,
回答1:
The question is not very clear, but I would try to provide a better approach to deal with such situations.
Since waypoints are specified within the waypoints parameters and can consist of one or more address, I would recommend using a name instead of the geocoordinates separated by pipe (|). This would indeed reduce the risk of getting faulty results.
On the top of it you can put optimize:true as the first argument within the waypoints parameter to allow the Directions service to optimize the provided route by rearranging the waypoints in a more efficient order.
Here is an example.
https://maps.googleapis.com/maps/api/directions/json?origin=Adelaide,SA&destination=Adelaide,SA&waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA&key=API_KEY
For more details please refer to this official Google documentation.
回答2:
Google maps doesn't support this feature yet and there are some requests to add it but there is another way to perform this with here maps.
https://developer.here.com/documentation/routing/topics/example-route-avoiding-an-area.html
来源:https://stackoverflow.com/questions/31479796/avoid-some-coordinates-in-routes-using-google-directions-api-android