经纬网地理编码问题

发布于 2024-10-11 08:43:22 字数 98 浏览 6 评论 0原文

我正在尝试使用经纬网对地址进行地理编码,但遇到了一个恼人的问题。对美国地址进行地理编码时,该位置的区域属性是两个字母缩写而不是全名(OH 而不是俄亥俄州)。有什么办法可以找回全名吗?

I'm attempting to use Graticule to geocode an address but I'm running into an annoying problem. When geocoding an address in the US, the region attribute from the location is the two letter abbreviation instead of the full name (OH instead of Ohio). Is there any way to retrieve the full name?

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

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

发布评论

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

评论(1

风渺 2024-10-18 08:43:22

看起来 Graticule 只是传递来自各种服务的原始结果,仅规范化属性名称。因此,简短的答案是:仅使用当前在 Graticule 映射到该服务的区域的字段中返回全名的服务。

很长的答案(或者确实是建议)。

我会使用哈希替换该值,例如,

US_STATES = {
  'OH' => 'Ohio'
  [...]
}

my_loc.region = US_STATES[my_loc.region] || my_loc.region

可能希望将其包装在国家/地区检查中,但是您必须确保涵盖服务中所有可能的国家/地区值,例如,

if my_loc.country =~ /\A\s*(US|U\.?S\.?A)\s*\z/i

这会让您一些稳定性,因此更改服务或更改其结果的服务,以后不会让您感到惊讶。

如果您感觉勇敢,可以分叉 Graticule 并添加region_name和region_abbr方法(或类似的),因为当前的“区域”具有可变的含义/结果并发送拉取请求...

Looks like Graticule just passes through the raw results from the various services, only normalizing the attribute names. So the short answer is: only by using a service that currently returns the full name in the field Graticule is mapping to region for that service.

Long answer (or suggestion really).

I'd replace the value using a Hash, e.g.,

US_STATES = {
  'OH' => 'Ohio'
  [...]
}

my_loc.region = US_STATES[my_loc.region] || my_loc.region

Probably would want to wrap that in a check for country, but then you'd have to be sure to cover all the possible country values from the services, e.g.,

if my_loc.country =~ /\A\s*(US|U\.?S\.?A)\s*\z/i

That would get you some stability so changing services, or services changing their results, won't surprise you later on.

If you were feeling intrepid, could fork Graticule and add region_name and region_abbr methods (or the like) since the current 'region' has variable meanings/results and send a pull request...

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