Question :
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.
Answer :
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) {
}