Google 地图 V3 中没有设定目的地的最短路线?

发布于 2024-09-29 06:00:01 字数 432 浏览 2 评论 0原文

所以我只是学习 javascript 来搞乱 Google 地图 API。我想知道是否有人对我遇到的这个问题有一个优雅的解决方案。

Google 地图路线请求必须包含三项内容(出发地、目的地和旅行模式)。我的旅行模式将始终是驾驶。原点始终是用户所在的位置。

但目的地需要有所不同。我有几个航路点,用户将访问,并希望根据选择的航路点和用户所在位置提供可能的最短行程,在其中一个航路点结束路线(例如:ABC 或 ACB,但始终为 Axx. ..x)。

除了计算每条可能的路径并查看哪一条距离最短(或时间,或我正在评估的任何内容)之外,还有其他可能的方法吗?看起来这成本会高得令人望而却步(O(n!))。

编辑:将建议的 optimizationWaypoints 标志设置为 true 后,这将成为 O(n) 问题而不是 O(n!) 问题,但现在我遇到了在太短的时间内发出太多请求的问题。

So I'm just learning javascript to mess with the Google Maps API. I was wondering if anyone had an elegant solution to this problem I'm running into.

A Google Maps route request must contain three things (origin, destination, and travelMode). My travelMode will always be DRIVING. The origin will always be wherever the user is located.

The destination though, needs to vary. I have several waypoints and the user will visit, and would like to provide the shortest trip possible depending on what waypoints are selected and where the user is, ending the route at one of the waypoints (eg: ABC or ACB, but always Axx...x).

Is there any possible way to do this other than calculating every possible path and seeing which has the shortest distance (or time, or whatever I'm evaluating on)? It seems like that would be prohibitively costly (O(n!)).

edit: With the suggested optimizeWaypoints flag set to true this becomes a O(n) problem instead of O(n!), but now I have issues with issuing too many requests in too short of a time period.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

铁憨憨 2024-10-06 06:00:01

谷歌路线中有一个设置可以提供优化路线(optimizeWaypoints - http ://code.google.com/apis/maps/documentation/javascript/services.html#Directions )您只需在路线对象中将其设置为 true

There is a setting in google directions to provide optimized route (optimizeWaypoints - http://code.google.com/apis/maps/documentation/javascript/services.html#Directions ) you simply set it to true in your directions object

○愚か者の日 2024-10-06 06:00:01

如果您想要最短路线,您可以首先调用 Google distanceMatrix API 并获取停靠点的排序列表。

然后使用排序列表调用 API 指令。

If you want the shortest route you can call first to Google distanceMatrix API and get the sort list of stops.

Then call to API directions with the sort list.

南七夏 2024-10-06 06:00:01

一个简单的解决方案是将出发地和目的地指定为相同的,并要求 Google 地图根据所有其他航点优化路线。它通常会首先到达最远点,或者最后到达最远点,然后返回原点。然后,您可以在不优化的情况下发出另一个请求,这次将目的地指定为最后一个优化的航路点。

A simple solution would be to specify Origin and Destination as the same and ask Google Maps to optimize the route based on all other waypoints. It will usually either go to the farthest point first, or last, then come back to the origin. You could then make another request without optimizing, this time specifying the Destination as the last optimized waypoint.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文