Google API: Google Place Autocomplete for Postal (Zip) Code using JavaScript

Last Reply 28 days ago By dharmendr

Posted one month ago

https://www.aspsnippets.com/Articles/Get-Client-IP-Address-and-Location-in-ASPNet-using-C-and-VBNet.aspx

using this API can we make auto complete extender, so in textbox if user type zipcode it shows city, and if user type initial of city it also shows city.

i want whether i type zipcode or city name in textbox it populates city name in textbox.

You are viewing reply posted by: dharmendr 28 days ago.
Posted 28 days ago

Hi nauna,

Displaying city name not possible.

But based on zipcode or city name you can populate the address.

Refer below sample code.

HTML

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=places&key=AIzaSyBE1J5Pe_GZXBR_x9TXOv6TU5vtCSmEPW4"></script>
<script type="text/javascript">
    window.onload = function () {
        var postal = document.getElementById('postalCode');
        var options = { types: ['(regions)'] }
        var autocomplete = new google.maps.places.Autocomplete(postal, options);
    }
</script>
<input id="postalCode" type="text" size="50" autocomplete="off">

Demo