2

Its possible to find list of state based on selected country..

Here i have attached some sample code

 $("#state").keypress(function(){
            var input = document.getElementById('state');
            //var c1=$("#country").val();
            var c1="us";
           // alert(c1);
            var options = {componentRestrictions: {country: c1}};  
            new google.maps.places.Autocomplete(input, options);
            });

if i set country is "us" ,its working but not for other country..

How to find state based on selected country?

Please any one help to me.....

1 Answers1

0

ISO 3166-1 alpha-2 can be used to restrict results to specific groups. Currently, you can use componentRestrictions to filter by country.

The country must be passed as as a two character, ISO 3166-1 Alpha-2 compatible country code.

Officially assigned country codes

read this source answered by @Francois

Try this code snippet, i created this, may be a little help for you.

$(document).ready(function () {
    var options = {
        types: ['(cities)'],
        componentRestrictions: {
            country: "us"
        }
    };
    var input = document.getElementById('autocomplete');
    new google.maps.places.Autocomplete(input, options);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://maps.googleapis.com/maps/api/js?libraries=places"></script>
<label for="autocomplete">Please Insert an address:</label>
<br>
<input id="autocomplete" type="text" size="50">
Community
  • 1
  • 1
Eko Junaidi Salam
  • 1,663
  • 1
  • 18
  • 26