hrishi
hrishi

Reputation: 1656

Get ZIP codes of particular country using google map

I am using maps.googleapis.com/maps/api in codeigniter to display auto complete location when user types zip address. I have two input field from first user will select country and in second filed he will type his zip code and from google autocomplete he will select his address.

    var directionsService = new google.maps.DirectionsService();
        google.maps.event.addDomListener(window, 'load', function () {
        new google.maps.places.SearchBox(document.getElementById('zip'));
        directionsDisplay = new google.maps.DirectionsRenderer({ 'draggable': true });
    });

It is working fine but now I want to show zip codes only from selected country. Means if user select Australia as country and type zip like 2127 then google api should show addresses in Australia having 2127 in address

Upvotes: 0

Views: 880

Answers (2)

xomena
xomena

Reputation: 32178

I would also add to previous answer that there is a feature request in the public issue tracker to extend components restrictions for places autocomplete (make it similar to Geocoding API)

https://code.google.com/p/gmaps-api-issues/issues/detail?id=4433

If you are interested in this feature request please star it to express your interest and receive updates from Google.

Upvotes: 3

Matej P.
Matej P.

Reputation: 5383

Google maps JS api provides two kinds of widgets for autocomplete. One is google.maps.places.SearchBox you are using, which only offers restriction by Latitude and Longitude bounds and then there is google.maps.places.Autocomplete which provides country restriction (and much more), eg. like this:

var input = document.getElementById('searchTextField');
var options = {
  componentRestrictions: {country: 'au'}
};

autocomplete = new google.maps.places.Autocomplete(input, options);

For more information about advantages/disadvantages of both approaches see the docs (check section "Summary of classes") and choose the best approach for your needs.

Upvotes: 3

Related Questions