Search code examples
javascriptgoogle-mapsgoogle-maps-api-3

Limit Google Maps Autocomplete to European boundaries


I am using basic Google Maps autocomplete:

    function initAutocomplete() {
        autocomplete = new google.maps.places.Autocomplete(
                (document.getElementById('autocomplete_1')),
                {types: ['(cities)']});
        autocomplete.addListener('place_changed', fillInAddress);
    }

It works totally fine, but I want to LIMIT the RESULTS to only European places. I could do it with the component Region filter but it limits me to 5 countries. Europe has 20+ countries. How to limit?

Edit: European including the UK :)


Solution

  • Here is a wild guess I can do using the documentation :

    function initialize() {
        var options = {
          bounds: myCustomEuropeBounds,
          strictBounds: true,
          types: ['(cities)']
         };
    
        new google.maps.places.Autocomplete(document.getElementById('autocomplete'), options);
    }
    

    The only thing left should be to define the bounds of Europe, which I let you find out by yourself :)

    Hope it helped !