-1

I'm currently trying to implement an autocomplete location field but I'm unable to figure out how to get it working.

Here is an example of what I'm trying to accomplish, except the map, I just need to enter a location and save the data to a model. Unfortunately the linked repo's example only shows how to use simple_form_for. I'm currently using bootstrap_form_for and can't figure out how to make it work.

Same with gmaps-autocomplete-rails and using semantic_form_for.

I'm still trying to figure out where all the .js goes, and how it's setting up / working together with Rails.

Any examples or tutorials would be greatly appreciated.

Thanks for your help.

1 Answer 1

3

Its pretty simple ..

  1. First ensure that you completed these steps deffined in https://github.com/kristianmandrup/gmaps-autocomplete-rails in the install section(no need of Customization section for beginers)
  2. Then place this in the view file

    = simple_form_for(resource) do |f| = f.input :address, :input_html =>{:id => 'gmaps-input-address'}, :placeholder => 'Start typing a place name...'

remember.. the id 'gmaps-input-address' should be present, and also provide the api key of google.

2
  • I'm not using simple_form_for. I'm using bootstrap_form_for and I'm worried that using both would add some issues. And how do I provide the API key in that example? What file does it go into, or how does it go into the f.input field?
    – advice
    Commented Jan 18, 2017 at 19:30
  • it may be simple_form_for, or it may be bootstrap_form_for, you can use any of them, but make sure that you have added an extra id = gmaps-input-address to that field. And for the api key, you can also do it without api key, in that case it will give a warning in console. simply add this line in the top of the view file where the input field is present <script async defer type="text/javascript" src="maps.googleapis.com/maps/api/js?sensor=false"></…>
    – Sumit Dey
    Commented Jan 19, 2017 at 4:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.