22

我只是好奇。也许是为了未来的项目。我想知道是否可以通过 Google API 从给定坐标中检索地址。

4

3 回答 3

42

是的。只需使用 Google Geocoding 和 Places API https://developers.google.com/maps/documentation/geocoding/https://developers.google.com/maps/documentation/places/

示例(源自此处):

var geocoder;

function initialize() {
  geocoder = new google.maps.Geocoder();
}

function codeLatLng(lat, lng) {
  var latlng = new google.maps.LatLng(lat, lng);
  geocoder.geocode({
    'latLng': latlng
  }, function (results, status) {
    if (status === google.maps.GeocoderStatus.OK) {
      if (results[1]) {
        console.log(results[1]);
      } else {
        alert('No results found');
      }
    } else {
      alert('Geocoder failed due to: ' + status);
    }
  });
}

google.maps.event.addDomListener(window, 'load', initialize);
于 2012-04-04T10:07:09.397 回答
23

可以通过向地理编码端点发送简单的 GET 请求来访问此信息。

例如点击https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=API_KEY会产生以下响应:

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "277",
               "short_name" : "277",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Bedford Avenue",
               "short_name" : "Bedford Ave",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Williamsburg",
               "short_name" : "Williamsburg",
               "types" : [ "neighborhood", "political" ]
            },
            {
               "long_name" : "Brooklyn",
               "short_name" : "Brooklyn",
               "types" : [ "sublocality", "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" ]
            }
         ],
         "formatted_address" : "277 Bedford Avenue, Brooklyn, NY 11211, USA",
         "geometry" : {
            "location" : {
               "lat" : 40.714232,
               "lng" : -73.9612889
            },
            "location_type" : "ROOFTOP",
            "viewport" : {
               "northeast" : {
                  "lat" : 40.7155809802915,
                  "lng" : -73.9599399197085
               },
               "southwest" : {
                  "lat" : 40.7128830197085,
                  "lng" : -73.96263788029151
               }
            }
         },
         "place_id" : "ChIJd8BlQ2BZwokRAFUEcm_qrcA",
         "types" : [ "street_address" ]
      },

  ... Additional results[] ...

https://developers.google.com/maps/documentation/geocoding/intro#reverse-example

于 2015-09-24T09:51:31.947 回答
2

TomTom 地图 API提供了一个反向地理编码端点,该端点给出了一个结构化的 JSON。

您可以使用API Explorer进行尝试。

例如 :

curl -X GET "https://api.tomtom.com/search/2/reverseGeocode/37.8328,-122.27669.json?key=*****" -H "accept: */*"

会得到你

{
  "summary": {
    "queryTime": 6,
    "numResults": 1
  },
  "addresses": [
    {
      "address": {
        "buildingNumber": "1001",
        "streetNumber": "1001",
        "routeNumbers": [],
        "street": "42nd Street",
        "streetName": "42nd Street",
        "streetNameAndNumber": "1001 42nd Street",
        "countryCode": "US",
        "countrySubdivision": "CA",
        "countrySecondarySubdivision": "Alameda",
        "countryTertiarySubdivision": "Oakland",
        "municipality": "Oakland, Emeryville",
        "postalCode": "94608",
        "municipalitySubdivision": "Oakland, Emeryville",
        "country": "United States",
        "countryCodeISO3": "USA",
        "freeformAddress": "1001 42nd Street, Emeryville, CA 94608",
        "boundingBox": {
          "northEast": "37.832893,-122.276230",
          "southWest": "37.832777,-122.277006",
          "entity": "position"
        },
        "countrySubdivisionName": "California",
        "localName": "Emeryville"
      },
      "position": "37.832844,-122.276688"
    }
  ]
}

您可以获得免费的 API KEY(无需信用卡)并尝试我们的教程

披露:我受雇于 TomTom。

于 2019-05-28T07:50:55.493 回答