Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restricting Google Map API to show only Cities, States & Country

I am new to Google Map APIs.. I wish to use dropdown where user will type location and correspondingly google will give suggestions.. but problem is i dont want Google to give Street & District names..I want only City, State & country names to be autosuggested..My code is as follows

    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=places&language=en-AU"></script>
    <script>
        var autocomplete = new google.maps.places.Autocomplete($("#address")[0], {});

        google.maps.event.addListener(autocomplete, 'place_changed', function() {
            var place = autocomplete.getPlace();
            console.log(place.address_components);
        });
    </script>
</body>

How to get only City & Country name from the API ? Thanks In advance

like image 408
Jigar Jain Avatar asked Nov 01 '25 04:11

Jigar Jain


1 Answers

Add 'regions' to the options in the constructor:

var acOptions = {
        types: ['(regions)']
    };

var autocomplete = new google.maps.places.Autocomplete($("#address")[0], acOptions);
like image 81
Marcelo Avatar answered Nov 04 '25 21:11

Marcelo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!