Nov 14, 2013

Convert coordinates to street address (reverse geocoding) via Google Maps API

Because most articles on this topic are quite outdated, here is a quick tip on how to do reverse geocoding with the help of Google Maps API v3.

In fact, you don't even need an API, this can be done manually via browser, or by fetching the url with some script and parsing the result.

The link is in this format:
https://maps.googleapis.com/maps/api/geocode/json?latlng=[LAT,LON]&sensor=true

Example:
https://maps.googleapis.com/maps/api/geocode/json?latlng=45.668483,14.18955&sensor=true

The result can be in JSON or XML format.
Documentation: https://developers.google.com/maps/documentation/geocoding/#JSON

JSON example result:
{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "51",
               "short_name" : "51",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Kolodvorska cesta",
               "short_name" : "Kolodvorska cesta",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Pivka",
               "short_name" : "Pivka",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Slovenia",
               "short_name" : "SI",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "6257",
               "short_name" : "6257",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "Pivka",
               "short_name" : "Pivka",
               "types" : [ "postal_town" ]
            }
         ],
         "formatted_address" : "Kolodvorska cesta 51, 6257 Pivka, Slovenia",

No comments: