4

Possible Duplicate:
limiting google maps autocomplete to UK address only

If anyone with Google Maps API V3 experience can help me out it would be much appreciated - I've been stuck on this for hours.

I'm trying to get my autocomplete to return UK addresses only (because the site is based in the UK), but my code isn't working even though it appears as though I've done it right. I still get all other countries as suggestions.

Here's 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 bounds from - I have found the ones above on a forum but am not sure if they're 100% correct.

Below is my API include:

<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 have set a region and gl in the querystring. If you see my image below, you'll see the result I have. Yes, it's slightly more biased to the UK - but there's still Los Angeles appearing.

enter image description here

Any help would be much appreciated!

Community
  • 1
  • 1
Adam Moss
  • 5,582
  • 13
  • 46
  • 64

2 Answers2

5

Bear in mind that the setBounds() method in the Autocomplete class will set the preferred area within which to return Place results. Results are biased towards, but not restricted to, this area.

miguev
  • 4,481
  • 21
  • 41
2

You're using the wrong bounds it appears. Try these out:

(49.383639452689664, -17.39866406249996)

(59.53530451232491, 8.968523437500039)

andresf
  • 2,063
  • 1
  • 11
  • 7
  • 1
    That is much better - I'm still getting some French cities showing but at least it's a lot more accurate. May I ask how you find out these bounds? – Adam Moss Feb 04 '12 at 10:57