I'm having trouble adding the componentRestrictions parameter to the Google Maps Geocoder object. I'm using the JavaScript client-side api. Specifically, the administrativeArea
property isn't working for me. Docs say type is a string, and I've tried many combinations but still no luck.
Here is my Geocoding function:
function geocodeAddress(geocoder, resultsMap) {
var address = document.getElementById('address').value;
geocoder.geocode({'address': address, 'componentRestrictions': {administrativeArea: 'Maricopa County'}}, function(results, status) {
if (status === 'OK') {
resultsMap.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: resultsMap,
position: results[0].geometry.location
});
console.log(results)
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
I can get other componentRestriction properties to work, like the postalCode
and country
, but not administrativeArea
. Docs say the property matches all the administrative_area levels
, so I've tried using different US counties and different US states, but can't get it to work. I figure I'm getting the syntax wrong, any help would be much appreciated!