0

I have noticed that Google Maps API provide the ISO code as the short name for the country. However for regions it is quite variable... For instance if I want to check Madrid, Spain:

ISO-Code Spain: ES
ISO-Code Region of Madrid: MD (Google does not provide this one)
ISO-Code City of Madrid: M

And this is just an example. For Germany it does not return the ISO Codes for the cities.

How can we parse the location with our private database? Does the Google Maps API follow any standard for the codes?

1

ISO 3661-2 doesn't often apply to cities; Madrid is an exception.

The ISO code for Madrid the Autonomous community is ES-MD not just MD and the ISO code for Madrid the Province is ES-M not just M.

There are no cities defined for Germany under ISO 3661-2, only the 16 states

The Google API would therefore seem to be based on ISO 3661-2, except it seems to cut off the two letter country code.

0

Thank you very much... Sorry I did not explained it properly. Whereas it is true that when Google Maps API uses iso codes it is as you say... I still see an issue.

For the request: https://maps.googleapis.com/maps/api/geocode/json?&address=madrid&language=en

The json response is:

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "Madrid",
               "short_name" : "Madrid",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Madrid",
               "short_name" : "M",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Community of Madrid",
               "short_name" : "Community of Madrid",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Spain",
               "short_name" : "ES",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Madrid, Spain",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 40.5638447,
                  "lng" : -3.5249115
               },
               "southwest" : {
                  "lat" : 40.3120639,
                  "lng" : -3.8341618
               }
            },
            "location" : {
               "lat" : 40.4167754,
               "lng" : -3.7037902
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 40.5638447,
                  "lng" : -3.5249115
               },
               "southwest" : {
                  "lat" : 40.3120639,
                  "lng" : -3.8341618
               }
            }
         },
         "place_id" : "ChIJgTwKgJcpQg0RaSKMYcHeNsQ",
         "types" : [ "locality", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Community of Madrid",
               "short_name" : "Community of Madrid",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Madrid",
               "short_name" : "M",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Spain",
               "short_name" : "ES",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Community of Madrid, Madrid, Spain",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 41.16584470000001,
                  "lng" : -3.0529833
               },
               "southwest" : {
                  "lat" : 39.8847195,
                  "lng" : -4.579076
               }
            },
            "location" : {
               "lat" : 40.4167515,
               "lng" : -3.7038322
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 41.16584470000001,
                  "lng" : -3.0529833
               },
               "southwest" : {
                  "lat" : 39.8847195,
                  "lng" : -4.579076
               }
            }
         },
         "place_id" : "ChIJuTPgQHqBQQ0RgMhLvvNAAwE",
         "types" : [ "administrative_area_level_1", "political" ]
      }
   ],
   "status" : "OK"

}

As you can see, theadministrative level 1 does not have any code to identify it. Is there a way to get the any satandarised code rather than the internal id that the API provides?

  • you should add this to your original question using the edit link. As it is not an answer to your question it is likely to get deleted. – nmtoken Aug 17 '18 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.