bjorn2404 / jQuery-Store-Locator-Plugin

A store locator plugin using Google Maps API version 3
MIT License
495 stars 235 forks source link

How add autocomplete? #24

Closed MyLittlePolygon closed 8 years ago

MyLittlePolygon commented 10 years ago

Hi guys,

Very nice plugin @bjorn2404. and thanks to share w/ us ;) I'm trying to add autocomplete, but I can not make it work. Anyone know how to add autocomplete?

Thanks

bjorn2404 commented 10 years ago

How would you ideally want this to work? If a match was found with autocomplete would it just show that one location?

angeenes commented 9 years ago

I think it would be a nice enhancement, something more like typeahead.js autosuggestion/autocomplete

jotapee commented 9 years ago

If you need google places autocomplete is really really simple to add. If you're using default input IDs ("#bh-sl-address"), then do like this: 1) when you call Google maps API, simply call the places library https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places&region=US 2) apply the places lib to the address input: (function($) { $(document).ready(function() { var autocomplete; var geocoder; var input = document.getElementById('bh-sl-address'); var options = { componentRestrictions: {'country':'us'}, types: ['(cities)'] }; autocomplete = new google.maps.places.Autocomplete(input,options); }); })(jQuery);

3) You're good to go.

I don't think that the author should add this built in due to the simplicity of doing by yourself.

Good luck!

bjorn2404 commented 8 years ago

There is now an option in v2.4.2 of the plugin for Google Places autocomplete and an example file included