Rails gmaps4rails Map doesn't autoadjust

100 Views Asked by At

I followed the gmaps4rails v2 tutorial from youtube.

This is what happens...

enter image description here

enter image description here

enter image description here

Explanation: Randomly when I access to the view, it shows the maps partially and if I move the maps with the mouse (as the first two pictures) it never fills all the field... Sometimes after n tries (just pressing F5...) it displays correctly (third picture) but later with another page reloading, it's like the first pictures. I need to know what is happening.

View:

<div style='width: 600px;'>
    <div id="map" style='width: 600px; height: 300px;'></div>
  </div>
  <script type="text/javascript">
    handler = Gmaps.build('Google');
    handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
    markers = handler.addMarkers(<%=raw @hash.to_json %>);
    handler.bounds.extendWith(markers);
    //handler.fitMapToBounds();
    handler.getMap().setZoom(15);
    handler.map.centerOn(marker);
    });
  </script>

controller:

@hash = Gmaps4rails.build_markers(@users) do |user, marker|
    marker.lat user.latitude
    marker.lng user.longitude
end

model:

class User < ActiveRecord::Base
    geocoded_by :current_sign_in_ip
    after_validation :geocode
end

I've tried with setZoom and fitMapToBounds but nothing changes... I followed all the tutorial and github's guide.

UPDATE:

How could I show the users at the map in other model different to the user model?

0

There are 0 best solutions below