Search code examples
google-mapsgoogle-maps-api-3autocompletelimitrestrict

Restrict google maps/use strictBounds to autocomplete by region


I am using Google Maps Autocomplete and trying to restrict my results only to the Balkan region. As Google Maps currently have an option to restrict autocomplete to just 5 countries, this is not an option for me - trying to find a workaround. I found a solution for the EU, but cannot work out how to set it for the Balkan region.

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

Wondering if strictBounds can be an option?


Solution

  • For anyone coming to this question over a year later. You would need to use the bounds option for limiting to an area.

    Here is my code for restricting to a rectangle area over Europe.

    var defaultBounds = new google.maps.LatLngBounds(
        new google.maps.LatLng(35.929631, -25.022766),
        new google.maps.LatLng(71.344983, 49.860046)
    );
    
    autocomplete = new google.maps.places.Autocomplete(
        document.getElementById("element-id"),
        {
            bounds: defaultBounds,
            strictBounds: true,
            types: ['(regions)']
        }
    );
    

    You can use this tool to get your own rectangle area http://www.birdtheme.org/useful/v3tool.html