如何将 google Geocoding API 结果映射到简单的城市、地区、国家

发布于 2024-10-07 01:32:50 字数 323 浏览 0 评论 0原文

我在地图上有一些标记,当用户单击它们时,我使用谷歌地理编码器来获取地址信息。问题在于 Google 返回此数据的格式。我想以一致的格式显示地址,例如

  • 温哥华,不列颠哥伦比亚省,加拿大
  • 西雅图,华盛顿州,美国
  • 悉尼,新南威尔士州,澳大利亚

有人知道一种简单的方法来解析这些数据,所以我最终得到了一些很好的简单的json之类的

{"city":"Vancouver", "region":"British Columbia", "country":"Canada"}

谢谢。

I have some markers on a map and when the user click them I use the google geocoder to get the address information. The issue is the format that Google returns this data. I want to display the address in a consistent format such as

  • Vancouver, British Columbia, Canada
  • Seattle, Washington, United States
  • Sydney, New South Wales, Australia

does any one know a simple way to parse this data so I end up with some nice simple json like

{"city":"Vancouver", "region":"British Columbia", "country":"Canada"}

Thanks.

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

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

发布评论

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

评论(1

蓝眼睛不忧郁 2024-10-14 01:32:50

天哪,当我认为政治地理学如此简单的时候,日子真是美好极了。如果谷歌能够返回这样的数据,他们肯定会的。相反,您会得到一团混乱的地点、次地点、管理区域级别*、国家/地区等。

为了说明这一点,请考虑以下内容:

http://maps.googleapis.com/maps/api/geocode/json?address=11215&sensor=false

http://maps.googleapis.com/maps/api/geocode/json?address=10010& sensor=false

对于曼哈顿来说,你的状态还不错。您将获得行政区(曼哈顿)、城市(纽约)、县(纽约)和州(纽约)。对于布鲁克林来说,事情并不那么干净。您将获得行政区(布鲁克林)、县(国王)和州(纽约)。

现在,如果您再往长岛走一点路,就会发现更多乐趣:

http://maps.googleapis.com/maps/api/geocode/json?address=40.723464,%20-73.716282&sensor=false

在这种情况下,您会得到村庄(花卉公园)、城镇(亨普斯特德)、县(拿骚)和州(纽约),但一切都有点混乱。

这是一个州 20 英里内的变化。如果你摆脱这种情况,你的指望就更少了。在英国,我们最希望看到的伦敦将是大伦敦地区的一些较小的行政区。

Google 提供了深入而丰富的分类法来处理这种变化,但您仍然需要应用自己的规则来理解它(通常是在州与州和国家/地区级别)

Oh man, the days when I thought political geography was this simple were sweeter days. If Google could return data like this, they surely would. Instead you get a mess of locality, sublocality, administrative_area_level_*, country, etc.

To illustrate this, consider the following:

http://maps.googleapis.com/maps/api/geocode/json?address=11215&sensor=false

http://maps.googleapis.com/maps/api/geocode/json?address=10010&sensor=false

For Manhattan, you're in okay shape. You get the borough (Manhattan), the city (New York), the county (New York), and the state (New York). For Brooklyn, things aren't so clean. You get the borough (Brooklyn), the county (Kings), and the state (New York).

Now if you go a little ways out onto Long Island, you get more fun:

http://maps.googleapis.com/maps/api/geocode/json?address=40.723464,%20-73.716282&sensor=false

In this case you get the village (Floral Park), the town (Hempstead), the county (Nassau), and the state (New York), but everything is kind of muddled up.

This is the variation within 20 miles in one state. If you move out of that, you can count on even less. In the UK, what most of what we'd want to see as London, will be some smaller borough of Greater London.

Google provides a deep and rich taxonomy to deal with this variation, but you will still need to apply your own rules to make sense of it (often at the state by state and country by country level)

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