How do I filter Google Maps results for a specific region?

3

I have a route system that captures user data and maps routes on the map:

geocoder.geocode({ 
    'address': endereco + ', Brasil', 
    'region': 'BR' 
}, function (results, status) {}

The problem is that it is returning addresses from all over Brazil and in some cases even out of it.

How do I configure the script to search only in a specific city? Ex: Search only locations that are within Belo Horizonte.

    
asked by anonymous 04.05.2015 / 20:09

1 answer

4

You should use the componentRestrictions option and set the filter for the administrativeArea field, documentation here .

In this case your code would look like this:

geocoder.geocode({ 
    'address': endereco,
    'region': 'BR',
    'componentRestrictions': {
        'country': 'BR',
        'administrativeArea': 'Belo Horizonte'
    }
}, function (results, status) {

}

link

    
04.05.2015 / 20:40