1
votes

I am attempting to return autocomplete results limited to a type of regions -

the (regions) type collection instructs the Places service to return any result matching the following types: - locality - sublocality - postal_code - country - administrative_area_level_1 - administrative_area_level_2

[https://developers.google.com/places/web-service/autocomplete][1]

but also locked to a strictbounds around the EU. When I use type (cities) this same code works. When I change the type to regions it drops the strict bounds. Is regions incompatible with strictbounds? Am I missing something silly? Also dropping the region:'EU' param does nothing.

function setup_autocomplete(){

        //console.log( 'setting up autocomplete' );
        //setbounds around EU
        var circle = new google.maps.Circle({ center: new google.maps.LatLng( 54.0000, -4.0000 ), radius: 60000 });

        var input = document.getElementById('home-carousel-location-input') || false,
            options = {
                region:'EU',
                types: ['(regions)'],
                bounds: circle.getBounds(), 
                strictbounds: true 

            }, autocomplete;

        if( input ){

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

1

1 Answers

0
votes

It appears that your Places Autocomplete implementation is not quite correct as you are using the region: parameter which is not supported. Here is the list of supported options that can be set on an Autocomplete object.

You can remove the region: parameter. You can set the region restrictions by using strictbounds: and bounds: parameter.

autocomplete.setOptions({
    strictBounds: true,
    bounds: circle.getBounds(),
    types: ['(regions)']
});

You can try the sample jsbin demo here.

In the demo, I've set a fillColor: to the circle to visualize the radius and added a rectangle with also a fillColor: to visualize the strictbounds. The Places Autocomplete service will return any result matching the (regions) type within the bounds.