I want to show the current location of the user only on road(not beside of the road) while moving. I have used the LocationManager
to get the current location. But sometimes I am getting the location beside the road, with this, the location point on map is showing beside the road. Actually, I have to show his location on Road(if he is beside the road) only. I searched lot for this but didn't get any idea.
Example: How I am getting the current locations on map.
m
A---n-------B
here,
A is start point
B is end point
n is on road(current location for sometime)
m is beside road(current location)
But I would need the m also should be on road.
Please help me on this..
The google directions service will calculate from nearest road so calculate directions from current location to current location - returned starting location will be on a road.
But what if user genuinely is off-road in a shopping mall carpark for instance?
For that you need to use road API which will give you the path upon the road otherwise you will not get the accurate path.
Snap to Roads
The Google Maps Roads API takes up to 100 GPS points collected along a route, and returns a similar set of data, with the points snapped to the most likely roads the vehicle was traveling along. Optionally, you can request that the points be interpolated, resulting in a path that smoothly follows the geometry of the road.
Check Details Here
You need to call like this
https://roads.googleapis.com/v1/snapToRoads?path=-35.27801,149.12958|-35.28032,149.12907|-35.28099,149.12929|-35.28144,149.12984|-35.28194,149.13003|-35.28282,149.12956|-35.28302,149.12881|-35.28473,149.12836&interpolate=true&key=YOUR_API_KEY