ubilabs / geocomplete

jQuery Geocoding and Places Autocomplete Plugin
http://ubilabs.github.com/geocomplete/
MIT License
1.22k stars 406 forks source link

How to bind Google Places API to US Only Addresses? #87

Closed vmedia closed 10 years ago

vmedia commented 11 years ago

Hello,

I posted this over on stackoverflow, but hoping going to the source might be able to help me resolve this issue. Here it is as posted:

http://stackoverflow.com/questions/19941130/how-to-bind-google-places-api-to-us-only-addresses

This is a good example of my setup and the form style I am using. http://ubilabs.github.io/geocomplete/examples/form.html

My goal is to create a simple form that auto completes the form with city, state, once a user types in a valid zip code. It all works great, except that I cannot get it bound to US only addresses. On occasion, a valid 5 digit zip will be entered, but then auto populates to a non-US address.

To see what I mean, try typing "91333" in the example above, which is a CA zip code in the city of Pacoima. But you'll also see that it suggests Sweden and Slovakia as entries.

I've tried countless methods, including the country restriction: componentRestrictions: {country: "us"}.

I've followed Google's methods, they document. In their example, they seem to have it working:

http://googlegeodevelopers.blogspot.com.au/2012/05/faster-address-entry-with-google-places.html

But I think the solution has to be adapting what they have done into the GeoComplete Jquery plugin, as I have yet to get it to work.

Please help! Thanks in advance

tomtomau commented 10 years ago

Have you tried the following? Seems to work for me.

$(selector).geocomplete({
    ...
    country: 'US',
});