iOS 从邮政编码查找位置(纬度、经度)

发布于 2024-10-11 12:50:31 字数 46 浏览 3 评论 0原文

获取给定邮政编码的位置的最佳方法是什么?它适用于美国/加拿大以外的国家吗?谢谢

What could be the best way to get location for a given zipcode. Would it work for countries outside US/Canada .Thanks

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

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

发布评论

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

评论(3

蝶…霜飞 2024-10-18 12:50:31

使用 Google 地理定位 API(在 google.com/maps 上尝试一下):

输入瑞士邮政编码,例如:
CH-9014

或法国的:
FR-34000

或德语:
de-12101

或美国:
us-90210

或加拿大:
ca-J5Z 1A1

或中国:
示例的cn-100000

因此,

{
  "status": "OK",
  "results": [ {
    "types": [ "postal_code" ],
    "formatted_address": "9014 St Gallen, Switzerland",
    "address_components": [ {
      "long_name": "9014",
      "short_name": "9014",
      "types": [ "postal_code" ]
    }, {
      "long_name": "St Gallen",
      "short_name": "St Gallen",
      "types": [ "locality", "political" ]
    }, {
      "long_name": "Sankt Gallen",
      "short_name": "SG",
      "types": [ "administrative_area_level_1", "political" ]
    }, {
      "long_name": "Switzerland",
      "short_name": "CH",
      "types": [ "country", "political" ]
    } ],
    "geometry": {
      "location": {
        "lat": 47.4082855,
        "lng": 9.3323890
      },
      "location_type": "APPROXIMATE",
      "viewport": {
        "southwest": {
          "lat": 47.3991076,
          "lng": 9.3180504
        },
        "northeast": {
          "lat": 47.4199564,
          "lng": 9.3543340
        }
      },
      "bounds": {
        "southwest": {
          "lat": 47.3991076,
          "lng": 9.3180504
        },
        "northeast": {
          "lat": 47.4199564,
          "lng": 9.3543340
        }
      }
    }
  } ]
}

瑞士邮政编码 9014 对应于 appx。到此位置:

"lat": 47.4082855,
"lng": 9.3323890

请在此处查看我对地理定位 API 的回答:
如何获取 GLatLng 对象预先在谷歌地图中输入地址字符串?

Use the Google geolocating API (try it out on google.com/maps):

Input for a Swiss ZIP code for example:
CH-9014

or a french one:
FR-34000

or german:
de-12101

or US:
us-90210

or canada:
ca-J5Z 1A1

or china:
cn-100000

for example:

yields

{
  "status": "OK",
  "results": [ {
    "types": [ "postal_code" ],
    "formatted_address": "9014 St Gallen, Switzerland",
    "address_components": [ {
      "long_name": "9014",
      "short_name": "9014",
      "types": [ "postal_code" ]
    }, {
      "long_name": "St Gallen",
      "short_name": "St Gallen",
      "types": [ "locality", "political" ]
    }, {
      "long_name": "Sankt Gallen",
      "short_name": "SG",
      "types": [ "administrative_area_level_1", "political" ]
    }, {
      "long_name": "Switzerland",
      "short_name": "CH",
      "types": [ "country", "political" ]
    } ],
    "geometry": {
      "location": {
        "lat": 47.4082855,
        "lng": 9.3323890
      },
      "location_type": "APPROXIMATE",
      "viewport": {
        "southwest": {
          "lat": 47.3991076,
          "lng": 9.3180504
        },
        "northeast": {
          "lat": 47.4199564,
          "lng": 9.3543340
        }
      },
      "bounds": {
        "southwest": {
          "lat": 47.3991076,
          "lng": 9.3180504
        },
        "northeast": {
          "lat": 47.4199564,
          "lng": 9.3543340
        }
      }
    }
  } ]
}

So the swiss ZIP code 9014 corresponds appx. to this location:

"lat": 47.4082855,
"lng": 9.3323890

See my answer on the geolocating API here:
How to get GLatLng object from address string in advance in google maps?

甜味拾荒者 2024-10-18 12:50:31

GeoNames 提供多种邮政编码地理编码服务,包括搜索给定邮政编码的位置。他们支持许多不同的国家。

您可能对邮政编码服务的地名查找最感兴趣

GeoNames offers a number of various zipcode geocoding services, including search for the location of a given zipcode. They support a number of various countries.

You would probably be most interested in the Placename Lookup for postalcode service

最初的梦 2024-10-18 12:50:31

Google 的 API 带有一些相当讨厌的限制。根据 @Claus Broch 的建议,最好使用 GeoNames 等开源资源。

我添加这个答案也是为了注意到 MapQuest 最近为 OpenStreetMap 数据提供了一个 API。它不进行(据我所知)邮政编码搜索,但位置名称、方向、海拔等都可以自由查询。我最近发现了它,我计划尽快用它替换我对谷歌地图 API 的调用。

http://developer.mapquest.com/web/products/open

Google's API comes with some fairly nasty restrictions. Better to use open sources like GeoNames per @Claus Broch's suggestion.

I'm adding this answer to also note that MapQuest has recently put up an API to OpenStreetMap data. It doesn't do (as far as I can tell) zip code searching, but location names, directions, altitude etc are all freely queryable. I recently discovered it an I plan on replacing my calls to google maps API with it as soon as I can.

http://developer.mapquest.com/web/products/open

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