Search code examples
google-mapsgoogle-maps-api-3google-geocoder

google.maps.Geocoder.geocode not always returns Australian postcode


I'm using the google.maps.Geocoder class to resolve Australian addresses entered into a free form input field:

  1. pass the entered address (such as "Parramatta") in the google.maps.GeocoderRequest.address field,
  2. call google.maps.Geocoder.geocode
  3. and then show all returned google.maps.GeocoderResult.formatted_address fields to the user so they can select one.

Problem is that the returned formatted_address fields not always contains the postcode.

Pass "Parramatta" into google.maps.GeocoderRequest.address -> 
    receive formatted_address "Parramatta NSW, Australia"

Pass "Strathfield" into google.maps.GeocoderRequest.address -> 
    receive formatted_address "Strathfield NSW 2135, Australia"

Looks to me like this is a fault in Google's database, but I'm not sure.

Is there a way to resolve addresses that always gives you the postcode?


Solution

  • If you reverse geocode the location returned for Parramatta, it does contain a post code:

    {
      "long_name": "2150",
      "short_name": "2150",
      "types": [
        "postal_code"
      ]
    }
    

    That is correct according to Wikipedia