如何使用谷歌地图 API 检查路线之间是否存在某个地点
您好,我正在开发一个关于拼车的项目(用户可以提供电梯并乘坐电梯往返于人们之间),这个问题可以通过一个示例更好地理解
示例:
假设一个人 A 从 startA 到 endA 旅行,并准备在他的车里提供一些座位。那么一个人 B 是这样的,他的起始位置 startB 在 startA 到 endA 之间,而他的 endB 可能会也可能不会位于 startA 到 endA 之间。
然后如何使用谷歌地图API检查startB是否在startA到endA之间
我正在用 PHP 做我的项目。
hi i am developing a project on carpooling(users can offer lift and take lift to/from people) the problem can be better understood by an example
example:
suppose a person A is travelling from a place startA to endA and is ready to offer some seats in his car.then a person B is such that,his start position startB is between startA to endA and his endB may or may not be in between startA to endA.
then how to check whether startB is in between startA to endA using google maps api
I am doing my project in PHP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这听起来像是“沿路线搜索”问题,Google 地图 API 对此没有完全匹配,但有一种方法可能足以满足您的目的。
让我假设您可以将计算委托给浏览器的 JavaScript 引擎。然后,您可以请求从 startA 到 endA 的路线并使用 RouteBoxer< /a> 的阈值 T1 是人 A 愿意偏离原始路线多远才能选择人 B。
利用该阈值,您可以构建一组边界框以沿着从 startA 开始的路线进行搜索到距离 T1 内的 startB 并检查 startB 是否包含在这些框之一中。
还有一个阈值 T2,即 B 愿意离开 endB 的距离,但是您可以通过请求(在不同的请求中)从 endA 到 endB 的驾驶和/或步行方向来轻松计算该阈值。如果上述情况(startB 距离路线在 T1 范围内)为真,但从 endA 到 endB 的距离大于 T2,那么您可以警告人 B 或完全放弃该路线。
这个项目听起来很有趣,但让我警告您一件事:您不想使用 PHP 从您自己的服务器向 Google Maps API(特别是 Directions API)发送请求。当用户实时提供输入时则不然。相反,您应该让每个用户的浏览器使用 JavaScript 来执行请求。否则,当您的网站变得流行时,它将耗尽每日的服务限额。有关详细信息,请阅读地理编码策略。
This sounds like the "search along route" problem, to which the Google Maps APIs have no exact match, but there is an approach that may work well enough for your purpose.
Let me assume you can delegate the calculations to the browser's JavaScript engine. Then you can request directions from startA to endA and use RouteBoxer with a threshold T1 of how far is person A willing to deviate from the original route in order to pick person B.
With that threshold, you can build a set of bounding boxes to search along the route from startA to startB within distance T1 and check whether startB is contained by one of those boxes.
There is also the threshold T2 of how far from endB is person B willing to be dropped, but that one you can calculate easily by requesting (in different requests) driving and/or walking directions from endA to endB. If the above (startB is within T1 from the route) is true but the distance from endA to endB is greater than T2, then you could either warn person B or drop the route altogether.
This project sounds like a lot of fun, but let me warn you about one thing: you don't want to send requests to the Google Maps APIs (specially the Directions API) from your own server, using PHP. Not when the inputs are provided by users in real time. Instead, you should let each user's browser do the requests, using JavaScript. Otherwise, when your site grows popular it will run out of daily allowance for the service. Read the Geocoding Strategies for more.