How to find if a geo-location is on a road between two points?

痴心易碎 提交于 2020-01-16 18:34:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!