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

javascript loading issues #531

Closed melancholyfleur closed 7 years ago

melancholyfleur commented 7 years ago

I'm using Rails 5, Ruby 2.3.1

When I load the javascript files in my application layout as such:

    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
    <script src="//maps.google.com/maps/api/js?v=3.24&key=AIzaSyApYuALMmarnd3m1akAvjCXH3wVAFlEKV4"></script>
    <script src="//cdn.rawgit.com/mahnunchik/markerclustererplus/master/dist/markerclusterer.min.js"></script>

Then I get the following error: Uncaught ReferenceError: google is not defined

When I switch it around a bit:

    <script src="//maps.google.com/maps/api/js?v=3.24&key=AIzaSyApYuALMmarnd3m1akAvjCXH3wVAFlEKV4"></script>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
    <script src="//cdn.rawgit.com/mahnunchik/markerclustererplus/master/dist/markerclusterer.min.js"></script>

I get this error: Uncaught ReferenceError: MarkerClusterer is not defined

And last option:

    <script src="//maps.google.com/maps/api/js?v=3.24&key=AIzaSyApYuALMmarnd3m1akAvjCXH3wVAFlEKV4"></script>
    <script src="//cdn.rawgit.com/mahnunchik/markerclustererplus/master/dist/markerclusterer.min.js"></script>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>

Gives us this error: Uncaught TypeError: Cannot read property 'offsetWidth' of null

I think this indicates a loading order issue, but I'm not sure in the last how to solve it. Please let me know if you'd like more info. Thanks!

apneadiving commented 7 years ago

Your last try is the proper one, and you get a proper js error which probably means you are trying to create a map on an undefined element in the dom. See http://stackoverflow.com/questions/11740663/google-map-api-uncaught-typeerror-cannot-read-property-offsetwidth-of-null