본문 바로가기
MS Azure, Google Cloud Platform

GPS to Address (Google Reverse Geocoding)

by swconsulting swconsulting 2018. 11. 8.


https://developers.google.com/maps/documentation/geocoding/intro#ReverseGeocoding




Example of Reverse Geocoding

The following query contains the latitude/longitude value for a location in Brooklyn:

https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY

Note: Ensure that no space exists between the latitude and longitude values when passed in the latlngparameter.

The above query returns the following result:

{
   
"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[] ...

Note that the reverse geocoder returned more than one result. The "formatted_address" results are not just postal addresses, but any way to geographically name a location. For example, when geocoding a point in the city of Chicago, the geocoded point may be denoted as a street address, as the city (Chicago), as its state (Illinois) or as a country (The United States). All are "addresses" to the geocoder. The reverse geocoder returns any of these types as valid results.

The reverse geocoder matches political entities (countries, provinces, cities and neighborhoods), street addresses, and postal codes.

The full list of formatted_address values returned by the previous query is shown below.

"formatted_address" : "277 Bedford Avenue, Brooklyn, NY 11211, USA",
"formatted_address" : "Grand St/Bedford Av, Brooklyn, NY 11211, USA",
"formatted_address" : "Grand St/Bedford Av, Brooklyn, NY 11249, USA",
"formatted_address" : "Bedford Av/Grand St, Brooklyn, NY 11211, USA",
"formatted_address" : "Brooklyn, NY 11211, USA",
"formatted_address" : "Williamsburg, Brooklyn, NY, USA",
"formatted_address" : "Brooklyn, NY, USA",
"formatted_address" : "New York, NY, USA",
"formatted_address" : "New York, USA",
"formatted_address" : "United States",

Generally, addresses are returned from most specific to least specific; the more exact address is the most prominent result, as it is in this case. Note that we return different types of addresses, from the most specific street address to less specific political entities such as neighborhoods, cities, counties, states, etc. If you wish to match a specific type of address, see the section below on restricting results by type.

Note: Reverse geocoding is an estimate. The geocoder will attempt to find the closest addressable location within a certain tolerance. If no match is found, the geocoder will return zero results.

Reverse Geocoding Filtered by Type

The following example filters the addresses returned to include only those with a location type of ROOFTOP and an address type of street_address.

https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&location_type=ROOFTOP&result_type=street_address&key=YOUR_API_KEY

Note: These filters are only valid for reverse geocoding.

Reverse Geocoding Responses

The format of the reverse Geocoding response is the same as the Geocoding response. See Geocoding Responses. Below are the status codes possible in a reverse geocoding response.

Reverse Geocoding Status Codes

The "status" field within the Geocoding response object contains the status of the request, and may contain debugging information to help you track down why reverse geocoding is not working. The "status" field may contain the following values:

  • "OK" indicates that no errors occurred and at least one address was returned.
  • "ZERO_RESULTS" indicates that the reverse geocoding was successful but returned no results. This may occur if the geocoder was passed a latlng in a remote location.
  • "OVER_QUERY_LIMIT" indicates that you are over your quota.
  • "REQUEST_DENIED" indicates that the request was denied. Possibly because the request includes a result_type or location_type parameter but does not include an API key or client ID.
  • "INVALID_REQUEST" generally indicates one of the following:
    • The query (addresscomponents or latlng) is missing.
    • An invalid result_type or location_type was given.
  • "UNKNOWN_ERROR" indicates that the request could not be processed due to a server error. The request may succeed if you try again.

Reverse Geocoding Plus Codes

The plus_code field within the Geocoding response object contains the plus code of the queried for latitude and longitude, as opposed to plus code fields in the reverse Geocoding responses which contain the plus codes of the individual responses.

댓글0