我们需要多少个字符来指定一个位置?

发布于 2024-12-26 04:22:40 字数 695 浏览 6 评论 0原文

大家好,我正在使用 Google Maps Directions API 和文档,它指出:

在 URL 编码之前,Directions API URL 的长度限制为 2048 个字符。由于某些路线服务网址可能涉及路径上的多个位置,因此在构建网址时请注意此限制。

我知道如果超过 2048 个字符,Google 会向我们发出 414 错误。但我想知道处理和通知用户他的请求太长的最佳方法是什么?我认为告诉用户“减少位置文本框中的字符数”似乎不太用户友好。

在我的应用程序中,我只允许用户指定起始位置、结束位置和最多 4 个路径点。大多数其他信息不是由用户提供的。除去其他参数的开销,可以说我可以允许用户输入总共 1800 个字符来表示他的起始位置、结束位置和 4 个路径点。

我在想将每个位置限制为 300 (1800 ÷ 6) 个字符是否安全,这样用户就永远没有机会指定超过 2048 个字符的请求?

重新表述这个问题,假设地球上每个可能位置的名称(我不需要支持地球以外的位置)是否在 300 个字符以内是否合乎逻辑?如果不是 300,那么安全的数字是多少?

Hi all I was playing around with the Google Maps Directions API and in the documentation, it states:

Directions API URLs are restricted to 2048 characters, before URL Encoding. As some Directions service URLs may involve many locations along a path, be aware of this limit when constructing your URLs.

I am aware that Google will give us a 414 error if we exceed 2048 characters. But I was wondering what's the best way to handle and inform the user that his request is too long? I do not think that it seems too user friendly to tell the user to "reduce the number of characters in the location textbox".

In my app, I'll only allow the user to specify a start location, an end location, and up to 4 waypoints. Most of the other information are not supplied by the user. Taking away the overhead of the other parameters, suffice it to say that I can allow the user to enter a total of 1800 characters for his start location, end location, and 4 waypoints.

I was thinking if it is safe to limit each location to 300 (1800 ÷ 6) characters, such that the user will never have the chance to specify a request which exceeds 2048 characters?

To rephrase the question, is it logical to assume that the name of every possible location on Earth (I do not require support for locations outside of Earth) is within 300 characters? If not 300, what's a safe number?

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

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

发布评论

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

评论(1

漫雪独思 2025-01-02 04:22:40

这并不能直接回答您的问题,但我建议对 url 长度限制采取以下解决方案:

如果 6 个位置的长度大于 1800 个字符,则首先对较长的位置进行地理编码。如果您发送地理编码而不是位置文本,则应该符合该限制。这样做的一个副作用是地理编码将位于方向文本而不是位置文本中。您可以通过修改从 API 返回的文本并将原始文本放回原处来解决此问题。API 为您提供了一种执行此操作的方法。这很痛苦,但这是绕过限制的一种方法。

This doesn't directly answer your question, but I would suggest the following work around to the url length limit:

If the length of your 6 locations is greater than 1800 characters, then geocode the longer locations first. If you send the geocodes instead of the location text, you should fit under the limit. One side effect of doing this is that the geocodes will be in the directions text instead of the location text. You can fix this by modifying the text that is returned from the API and put the original text back in. The API gives you a way to do that. It's a pain, but it's a way to get around the limitation.

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