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

this.setMap is not a function #450

Closed bourg-ismael closed 9 years ago

bourg-ismael commented 9 years ago

Hi, I have this error when I use the gem : this.setMap is not a function If I reload the page all is ok but the first time I access a page I have this error and a blue map.

Here my controller :

@clubs = Club.all.paginate(:page => params[:page], :per_page => 5)
    @post = Club.where(:latitude != nil)
    @hash = Gmaps4rails.build_markers(@post) do |club, marker|
      if club.latitude.present? && club.longitude.present?
        marker.lat club.latitude
        marker.lng club.longitude
        marker.infowindow club.description
      end
    end
  end

And my View :

<!-- GOOGLE MAP -->
<div id="map" class="col-md-12" style='height: 300px;'></div>
<!-- END GOOGLE MAP -->

<script src="//maps.google.com/maps/api/js?v=3.13&amp;sensor=false&amp;libraries=geometry" type="text/javascript"></script>
<script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js' type='text/javascript'></script>
<script>
    handler = Gmaps.build('Google');
    handler.buildMap({ provider: {scrollwheel: false}, internal: {id: 'map'}}, function(){
        markers = handler.addMarkers(<%=raw @hash.to_json %>);
        handler.bounds.extendWith(markers);
        handler.fitMapToBounds();
        handler.getMap().setZoom(15);
    });
</script>
apneadiving commented 9 years ago

I dont see any reason. I guess you have some stuff interfering with js? Turbolinks or alike?

bourg-ismael commented 9 years ago

Yes I use Turbolinks, how can I catch the problem ?

apneadiving commented 9 years ago

Not sure how never used that. Try to include all scripts in all pages. I dont know how to do smarter with this