Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

limiting google maps autocomplete to UK address only

Tags:

google-maps

I've been looking at the example on:

http://code.google.com/apis/maps/documentation/javascript/examples/places-autocomplete.html

and have decided to incorporate it into my site.

Is it possible to limit the addresses to UK addresses only?

like image 621
methuselah Avatar asked Aug 24 '11 17:08

methuselah


People also ask

Is google map limited to only one country?

we can allow only specific country to autocomplete search in google maps. We are using google map autocomplete for choosing address with latitude and longitude. but if you require to search only one country like in, us, uk etc then you can do it using setComponentRestrictions option in google map.

How do I limit a location on Google Maps?

You can limit the view able area and zoom level of the google map using limit panning settings. Google map plugin provides easiest way to limit panning/dragging so the map stays within certain bounds using limit panning settings. Step 1 Go to Add or Edit Map and scroll down to 'Limit Panning Settings' section.


2 Answers

Try this:

var input = document.getElementById('searchTextField');
var options = {
   types: ['(cities)'],
   componentRestrictions: {country: 'tr'}//Turkey only
};
var autocomplete = new google.maps.places.Autocomplete(input,options);
like image 167
Ercan Avatar answered Oct 30 '22 22:10

Ercan


You can't strictly/hard limit the locations that it finds, although there is a feature request in the system to do so, but you can set a 'bias' on the results. It's passed in as an argument to the autocomplete method as a google maps bounds object. Autocomplete will then favor locations within those boundaries. Note, however, that since this isn't a hard boundary, if there are matches for the search outside the boundaries it will return those.

From my usage it seems a bit buggy and can use some improvement - especially considering that anything outside your boundary is not tagged by proximity at all, so something one block outside the boundary is just as likely to show as something 1000 miles outside, so make sure you play around with getting the boundaries working right.

like image 30
James Alday Avatar answered Oct 31 '22 00:10

James Alday