Search code examples
androidgoogle-mapscoordinatedirections

Android google directions api ignore street side


I want to display the a route on a map and I have the coordinates for each waypoint in the route. The problem is, the coordinates are not that precise and it can occur that google thinks the waypoint is on the other street side, thus giving me a stupid route result. Is there any way to make google think that the waypoint is not on the other street side or optimize the waypoints?


Solution

  • I don't think you can track Google Maps to think it is not on the other side. But you can optimize your waypoints by using the snapToRoads function in Google Maps Roads API.

    enter image description here

    Even the path I draw is closer to the right to left part (upper/westbound) of the Charleston road, since I draw the points from left to right, the snapToRoads is able to tell I am actually going from left to right (eastbound).

    You should able to fix your lat/lng on your server by using their web API, which looks like:

    https://roads.googleapis.com/v1/snapToRoads?path=lat1,lng1|lat2,lng2|lat3,lng3
        &interpolate=true
        &key=API_KEY