存储完整的谷歌地图路线

发布于 2025-01-06 14:58:19 字数 943 浏览 2 评论 0原文

我希望能够轻松地在 Google 地图上存储和重新显示 Google 地图路线。假设从 A 点到 B 点,DirectionsResult 对象来自Google的信息沿路线有100个点,我希望能够存储这条路线并保证下次绘制它时方向将经过所有这些点。

我看到人们尝试这样做的方法是序列化整个 DirectionsResult 对象并将其存储在数据库中。然后,当我们想要重绘路线时,将字符串发送回去,对其进行 JSON.Parse,然后尝试将其提供给 DirectionsRenderer 对象,它将在地图上渲染方向。这种方法存在三个问题:

1)在序列化过程中丢失类型信息,并且由于 Google 缩小了对象,因此您无法使用类函数可靠地从对象中获取这些值。在最初序列化对象时,您需要首先使用数据访问器函数构建“占位符”对象,然后在稍后解析序列化字符串时重建 Google Maps 对象。

2)它在法律上是可疑的。谷歌地图服务条款说你不应该永久存储数据,从其他帖子看来这种方法违反了它。

3)对象可能很大,我序列化的一条路由超过了64KB。

我还考虑过尝试存储路径中的一些点,然后使用路径点重建它。这种方法可行,但免费 API 最多只能有 8 分,因此这不能保证超过这 8 分的准确性。此外,它还会沿着路线绘制路点标记,我认为这可能会让用户感到困惑。

是否有一种可接受的方法来存储 Google 地图的准确路线,或者 API 和 TOS 是否有意设计为防止这种情况发生?感谢您的帮助。

I want to be able to easily store and redisplay a Google Maps Directions Route on a Google Map. Let's say from point A to B, the DirectionsResult object from Google has 100 points along the route, I want to be able to store this route and guarantee the next time I paint it the directions will go through all of these points.

The way I have seen people trying to do it is to serialize the entire DirectionsResult object and store it in a database. Then when we want to redraw the route, send the string back up, JSON.Parse it, and then attempt to feed it to a DirectionsRenderer object which will render the directions on the map. This approach has three problems:

1) You lose type information during the serialization process, and since Google minnifies the objects, you aren't able to use class functions to get these values out of the object reliably. You need to first use data accessor functions to build 'place holder' objects when initially serializing the object, then rebuild the Google Maps objects when later parsing the serialized string.

2) It's legally dubious. The Google Maps TOS says you aren't supposed to store data permanently and it seems from other posts this approach violates it.

3) The object can be huge, one route I serialized was over 64KB.

I also thought about trying to store a few points from the path and then rebuilding it using Waypoints. This sort of works but you can only have at most 8 points for the free API, so this doesn't guarantee much accuracy beyond those 8 points. Furthermore, it then paints the waypoint markers along the route which I think could confuse the user.

Is there an accepted way to store exact routes from Google Maps, or are the API and TOS purposefully designed to prevent this? Thanks for the help.

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

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

发布评论

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

评论(2

—━☆沉默づ 2025-01-13 14:58:19

我认为这在法律上是值得怀疑的。事实上,它几乎肯定违反了服务条款。正如您所指出的,它是永久存储,其目的不是为了提高性能(与 10.1.3(b) 相反);但它也旨在显示方向而不通过 API 获取方向(与 10.1.1(a) 相反)。事实上,谷歌并没有让它变得简单,这意味着他们还没有授权这个用例。事实上,TOS 和 API 的设计目的就是让这样的存储变得困难(如果不是不可能的话)。

存储起点和终点并让API在您想再次显示路线时计算出路线是不是可以接受?

I believe this is legally dubious. In fact it almost certainly contravenes the Terms of Service. As you point out, it's permanent storage for purposes other than improving performance (contrary to 10.1.3(b)); but it's also intended to show directions without getting them via the API (contrary to 10.1.1(a)). The fact that Google have not made it easy means that they have not authorised this use case. In fact the TOS and the API are designed to make storage like this difficult if not impossible.

Would it not be acceptable to store start and end points and let the API work out the route when you want to display it again?

一花一树开 2025-01-13 14:58:19

看看 www.mapmyrun.com 他们正在使用谷歌地图 API 并且他们肯定会保留数据。然而,他们不太可能使用免费的 API。

Take a look at www.mapmyrun.com they are using the google maps api and they are certainly persisting the data. However, its unlikely they use the free API.

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