Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autocomplete Google Map V3 Places impossible to customize?

I narrowed autocomplete to a region and to a bounds that cover only Australia, but I am still receving autocomplete with Chile and China and other country out of the selected area. Does anyone have a good solution to work this problem? I also can't change the styling off Google autocomplete, it is a self generated Div with style tag that overcomes my style to autocomplete DIV? I started to use Geocoder and Jquery autocomplete to filter the results but it doesn't work as well as Google Autocomplete the results are less than google maps autocomplete?

I call the Library like this:

Here is the code of creating the auto complete:

    var defaultBounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(-47.5765257137462, 106.259765625),
    new google.maps.LatLng(-9.6, 179.359375));

    var options = {
      bounds: defaultBounds,
      types: ['geocode'],
      offset: 5
    };

    var input = document.getElementById('store-locator-header');

    var autocomplete = new google.maps.places.Autocomplete(input,options); 
like image 476
DaniMatos Avatar asked Sep 27 '11 00:09

DaniMatos


People also ask

How do I limit autocomplete results to country only?

Currently, you can use componentRestrictions to filter by country. The country must be passed as as a two character, ISO 3166-1 Alpha-2 compatible country code. Save this answer.


2 Answers

Nowadays, you can restrict to a country with:

componentRestrictions: {country: 'us'},

like image 176
John Jannotti Avatar answered Sep 18 '22 08:09

John Jannotti


When Adding Autocomplete with bounds, results are biased towards, but not restricted to, Places contained within these bounds. This is the same as when using Viewport Biasing in the Geocoding API. I'm afraid I don't have a method to filter out those suggestions that fall outside of the bounds.

like image 45
miguev Avatar answered Sep 19 '22 08:09

miguev