问题
I am a student working on an android application related to navigation trying to learn android programming. The application needs to search the geo-locations (latitude,longitude) among the ones available and find out which ones fall along the route the user is travelling.
For example, if the user is travelling from 37.422,-122.084058 to 37.422,-122.084058, then I should be able to search the points that fall along this route from the set of points that I have. How do I do that?
I am getting the route direction of the user from the google api
https://maps.googleapis.com/maps/api/directions/json?origin=Googleplex&destination=infinityloop=&key=your_api_key
I get the route in the form of legs and I have a set of geo-locations. I would like to find which geo-locations fall along the route of the user. Is there any way I can find it or any API that I can use ?
Any help is greatly appreciated. Thanks in advance :)
回答1:
There's already a lib for this: use isLocationOnPath with the polyline
you are getting from directions api response.
回答2:
Build a LatLngBound using the two points and pass in the geolocation point you want to check into LatLngBounds.contain().
来源:https://stackoverflow.com/questions/28908658/how-to-find-if-a-geo-location-is-on-a-road-between-two-points