Trying to work with the Google Autoplete without maps, but it's being troublesome.
<script>
var autoplete;
var countryRestrict = {country: 'NO', postalCode: '0365'}
function initAutoplete() {
autoplete = new google.maps.places.Autoplete(
(document.getElementById('address-field')),
{ types: ['address'],
ponentRestrictions: countryRestrict
});
}
</script>
<script src=";libraries=places&callback=initAutoplete"
async defer></script>
when I add postalCode
to countryRestrict it stops working, yet I see in their own example that they seem to be restricting it by using the example:
ponentRestrictions: {country: "AU", postalCode: "2000"}
Is it possible for me to limit the address autoplete to a given postal code?
Trying to work with the Google Autoplete without maps, but it's being troublesome.
<script>
var autoplete;
var countryRestrict = {country: 'NO', postalCode: '0365'}
function initAutoplete() {
autoplete = new google.maps.places.Autoplete(
(document.getElementById('address-field')),
{ types: ['address'],
ponentRestrictions: countryRestrict
});
}
</script>
<script src="https://maps.googleapis./maps/api/js?key=API-KEY&libraries=places&callback=initAutoplete"
async defer></script>
when I add postalCode
to countryRestrict it stops working, yet I see in their own example that they seem to be restricting it by using the example:
ponentRestrictions: {country: "AU", postalCode: "2000"}
https://developers.google./maps/documentation/javascript/examples/geocoding-ponent-restriction
Is it possible for me to limit the address autoplete to a given postal code?
Share Improve this question edited Mar 7, 2016 at 15:02 geocodezip 161k14 gold badges227 silver badges255 bronze badges asked Mar 7, 2016 at 10:55 Sebastian Jennings AlmnesSebastian Jennings Almnes 1,6082 gold badges20 silver badges33 bronze badges1 Answer
Reset to default 4Currently it's not possible, the only supported ponentRestriction for an Autoplete is country
(The linked example is an implementation of geocoding, where more ponentRestrictions are supported )
Adding other ponentRestrictions than the supported options results in a script-error which breaks the Autoplete