且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何找到特定路线上两点之间的距离?

更新时间:2022-03-10 23:30:05

我会这样解决:

1)两个GPS点之间的直接视线距离很简单,只需使用Location.distanceBetween()方法,你会在SO上找到数百个帖子.

1) The direct line of sight distance betweent two GPS points is simple, simply use Location.distanceBetween() method, you will find hundres of posts here on SO.

2) 路线的长度.这部分比较难.如果您对 google 的结果不满意:将您的公交路线存储为粗略的纬度/经度坐标序列(折线).每个街角一个点就足够了.然后找到路线上最近的点,简单的蛮力搜索应该足以完成您的任务.然后简单地从找到的路径点迭代到目的地点,并使用 distanceBetween() 方法进行总结.

2) The length of the route. This part is more difficult. If you are not happy with the result of google: Store your bus routes as rough sequence of lat/lon coordinates (a poly line). A point per street corner should be sufficient. Then find the nearest point on the route, a simple brute force search should be sufficent for your task. Then simply iterate from found route point till destination point, and sum up using the distanceBetween() method.