谷歌地图:如何获得国家,州/省/地区,具有经济/经济价值的城市? [英] Google Maps: how to get country, state/province/region, city given a lat/long value?

查看:202
本文介绍了谷歌地图:如何获得国家,州/省/地区,具有经济/经济价值的城市?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一份国家,州和地区名单。城市基于我拥有的纬度/经度值集合。我需要以保留层次结构并且没有重复的方式存储这些信息(例如美国和美国和美国是同一个国家;我只希望在我的数据库中有一个这样的国家实例) 。

I need a list of countries, states & cities based on a collection of lat/long values I have. I need to store this information in a manner that hierarchy is preserve and without duplicates (e.g. "USA" and "United States" and "United States of America" are the same country; I only want one instance of this country in my database).

这可能与Google Map API有关吗?

Is this possible to do with Google Map API?

推荐答案

您正在寻找的是反向地理编码。 Google通过 Google地理编码API 提供服务器端反向地理编码服务,你应该可以用于你的项目。

What you are looking for is called reverse geocoding. Google provides a server-side reverse geocoding service through the Google Geocoding API, which you should be able to use for your project.

以下是对以下请求的响应:

This is how a response to the following request would look like:


http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false

回应:

Response:

{
  "status": "OK",
  "results": [ {
    "types": [ "street_address" ],
    "formatted_address": "275-291 Bedford Ave, Brooklyn, NY 11211, USA",
    "address_components": [ {
      "long_name": "275-291",
      "short_name": "275-291",
      "types": [ "street_number" ]
    }, {
      "long_name": "Bedford Ave",
      "short_name": "Bedford Ave",
      "types": [ "route" ]
    }, {
      "long_name": "New York",
      "short_name": "New York",
      "types": [ "locality", "political" ]
    }, {
      "long_name": "Brooklyn",
      "short_name": "Brooklyn",
      "types": [ "administrative_area_level_3", "political" ]
    }, {
      "long_name": "Kings",
      "short_name": "Kings",
      "types": [ "administrative_area_level_2", "political" ]
    }, {
      "long_name": "New York",
      "short_name": "NY",
      "types": [ "administrative_area_level_1", "political" ]
    }, {
      "long_name": "United States",
      "short_name": "US",
      "types": [ "country", "political" ]
    }, {
      "long_name": "11211",
      "short_name": "11211",
      "types": [ "postal_code" ]
    } ],
    "geometry": {
      "location": {
        "lat": 40.7142298,
        "lng": -73.9614669
      },
      "location_type": "RANGE_INTERPOLATED",
      "viewport": {
        "southwest": {
          "lat": 40.7110822,
          "lng": -73.9646145
        },
        "northeast": {
          "lat": 40.7173774,
          "lng": -73.9583193
        }
      }
    }
  },

  ... Additional results[] ...

您也可以选择在xml中接收响应而不是json,只需在请求URI中用json替换xml即可:

You can also opt to receive the response in xml instead of json, by simply substituting json for xml in the request URI:


http://maps.googleapis.com/maps/api/geocode/xml?latlng=40.714224,-73.961452&sensor=false

就我所知,Google也会为地址组件返回相同的名称,特别是对于高级别名称,如国名和城市名称。尽管如此,请记住,虽然结果对于大多数应用程序非常准确,但您仍然可以发现偶尔的拼写错误或模糊的结果。

As far as I know, Google will also return the same name for address components, especially for high-level names like country names and city names. Nevertheless, keep in mind that while the results are very accurate for most applications, you could still find the occasional spelling mistake or ambiguous result.

这篇关于谷歌地图:如何获得国家,州/省/地区,具有经济/经济价值的城市?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆