apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.27k stars 382 forks source link

Where do I include the api scripts if I don't have maps on every page? #488

Closed simkessy closed 8 years ago

simkessy commented 8 years ago

I'm running into issues right now because the api is looking for the div with id='map' but I don't have maps on every page of my application, so it returns an error and breaks my other JavaScript.

I only have maps on one page and the map is a partial. I'm also using the places autocomplete api on every page so I've put that in my application.html.erb

If I put the maps specific script in the partials file, I run into errors regarding duplicate calls to the api:

You have included the Google Maps API multiple times on this page. This may cause unexpected errors. 
Uncaught ReferenceError: Gmaps is not defined(anonymous function) 
Uncaught TypeError: Cannot read property 'Autocomplete' of undefined
apneadiving commented 8 years ago

sure... beware how you include your js files and/or test if the div you need is present in the page before executing code.

Those issues are general js issues, not due to the library

simkessy commented 8 years ago

@apneadiving do you have any suggestions on how I could solve this please?