Google Maps API AutoComplete UK Only

Possible duplicate:
restrict Google Maps autocomplete to the UK address only

If anyone who has experience with the Google Maps V3 Maps API can help me, that would be very appreciated - I was stuck with this for hours.

I am trying to get autocomplete to only return UK addresses (because the site is based in the UK), but my code does not work, although it seems like I did it right. I still offer all other countries.

Here is my autocomplete code:

<script type="text/javascript"> function initialize() { var mapOptions = { center: new google.maps.LatLng(-0.12800500000003012, 51.508129), zoom: 13, mapTypeId: google.maps.MapTypeId.ROADMAP }; var bounds = new google.maps.LatLngBounds( new google.maps.LatLng(49.00, -13.00), new google.maps.LatLng(60.00, 3.00)); var input = document.getElementById('sei'); var autocomplete = new google.maps.places.Autocomplete(input); autocomplete.setBounds(bounds); } google.maps.event.addDomListener(window, 'load', initialize); </script> 

I'm not sure where to get the borders - I found the ones that were higher on the forum, but I'm not sure that they are 100% correct.

Below is my API:

 <script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=places,geometry&sensor=false&region=GB&gl=gb"></script> 

As you can see, I set the scope and gl to a querystring. If you see my image below, you will see the result that I have. Yes, it's a little more biased for the UK, but Los Angeles still appears there.

enter image description here

Any help would be greatly appreciated!

+4
source share
2 answers

Keep in mind that the setBounds() method in the Autocomplete class will set the preferred region in which Place results will be returned. Results are biased in direction, but not limited to , this area.

+5
source

You are using the wrong borders. Try:

(49.383639452689664, -17.39866406249996)

(59.53530451232491, 8.968523437500039)

+2
source

Source: https://habr.com/ru/post/1394645/


All Articles