如何找到特定路线上两点之间的距离? [英] How to find the distance between two points along a specific route?

查看:26
本文介绍了如何找到特定路线上两点之间的距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的大学开发一个 Android 应用程序,它可以帮助学生跟踪大学校车的当前位置,并为他们提供校车到达他们的预计时间.到目前为止,我得到了公共汽车的当前位置(通过公共汽车上的设备)和学生的位置.我被困在必须找到两个 GPS 坐标之间的距离的地方.我必须找到沿着特定路线"(即公共汽车所走的路径)的公共汽车和学生之间的距离.使用 Google Map API 并不总是能给出我想要的路线的距离.如何找到特定路线上两点之间的距离?

I'm developing an android app for my college that helps students track the current location of the college bus and also give them an estimated time when the bus might reach them. As of now I get the current location of the bus(via a device present on the bus) and the location of the student. I'm stuck at the point where I have to find the distance between the two GPS co-ordinates. I have to find the distance between the bus and the student "along a specific route" (i.e the path the bus takes). Using Google Map APIs will not always give the distance along the route I want. How do I find the distance between two points along a specific route?

推荐答案

我会这样解决:

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.

这篇关于如何找到特定路线上两点之间的距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆