When I try using componentRestrictions while geocoding:
geocoder.geocode({
address: address,
componentRestrictions: {
country: 'AU',
},
}
for:
address = 'Sydney 2000'
(case sensitive)
I get:
{
"results" : [],
"status" : "ZERO_RESULTS"
}
whereas, `address = 'sydney 2000'`
gives me the normal results object for Sydney
(Also works for basically every other Australian capital city in the format 'Melbourne 3000')
Whereas if I use regions:
geocoder.geocode({
address: address,
region: 'AU'
}
using `address = 'Sydney 2000'` (case sensitive) again gives me normal results object for Sydney
I haven't yet seen this fail for anything other than Sydney 2000
. So while I have options to work around this on my end, I'm also confused why it isn't working.
It looks like the issue that you are experiencing is a known issue reported in Google issue tracker
4-digit postal codes are hard to geocode (AT, AU, BE, CH, DK, NZ, SI)
According to engineers at Google
We are investigating a systemic issue that appears to make postal codes with 4 digits particularly difficult to find in the Geocoding API.
For best result, the recommended request format is to use Component Filtering and Region Biasing towards the desired country:
https://maps.googleapis.com/maps/api/geocode/json?skip_auth&components=postal_code:2725|country:AU®ion=AU
In Australia in particular, if feasible in your implementation, adding the administrative_area: filter helps with most postal codes in the 2000-2020 range. (taking into account that postal codes 2001-2005 and 2012-2014 are not in Google Maps at all)
https://maps.googleapis.com/maps/api/geocode/json?&components=country:AU|administrative_area:NSW|postal_code:2006
In other countries, wherever possible adding the locality filter would also help, as noted in #10.
We will keep you posted here.
I would suggest reading all bug's messages and starring the bug in order to subscribe to further notifications from Google.