Search code examples
ruby-on-railsrubyruby-on-rails-3google-mapsgmaps4rails

gmaps4rails showing blank map with map controls


Trying to get gmaps4rails to work in a rails 3 project. I have everything setup according to the demo but my view only shows the map controls on top of a gray background where the map should be. Tried it in chrome and safari. Any thoughts?

In the model:

acts_as_gmappable :process_geocoding => false

def gmaps4rails_address
  "#{address}, #{city}, #{state} #{zip}"
end

In the controller:

@venues = Venue.limit(5)
@venue_map_data = @venues.to_gmaps4rails

In the view:

<%= gmaps4rails(@venue_map_data) %>

In the application.html.erb layout:

<!DOCTYPE html>
<html>
<head>
  <title>MapTest</title>
  <%= stylesheet_link_tag :all %>
  <%= javascript_include_tag :defaults %>
  <%= csrf_meta_tag %>
  <%= yield :head %>
</head>
<body>
   <%= yield %>
   <%= yield :scripts %>
</body>
</html>

Javascript stuff:

<script src="/javascripts/gmaps4rails.js" type="text/javascript"></script> 
<script type="text/javascript" src='http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/src/markerclusterer_compiled.js'></script> 
<script type="text/javascript" charset="utf-8"> 
function gmaps4rails_init() {
    Gmaps4Rails.map_options.auto_adjust = true;
    Gmaps4Rails.initialize();
    Gmaps4Rails.markers = [{"longitude": "37.742956", "latitude": "-122.421695"},
           {"longitude": "37.742668", "latitude": "-122.421735"},
           {"longitude": "37.742578", "latitude": "-122.42178"},
           {"longitude": "37.742862", "latitude": "-122.421575"},
           {"longitude": "37.743123", "latitude": "-122.421485"}];
    Gmaps4Rails.create_markers();
    if(typeof gmaps4rails_callback == 'function') { gmaps4rails_callback(); }
}

function gmaps4rails_loadScript() {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "http://maps.google.com/maps/api/js?sensor=false&libraries=geometry&callback=gmaps4rails_init";
    document.body.appendChild(script);
}

window.onload = gmaps4rails_loadScript;

</script> 

Venue data gathered in @venues: name, address, city, state, zip, latitude, longitude
Altena Restaurant, 3346 Mission St, San Francisco, CA, 94110, -122.421695, 37.742956
LA Morena Latinoamericana, 3391 Mission St, San Francisco, CA, 94110, -122.421735, 37.742668
Costa Del Sol II, 3385 Mission St, San Francisco, CA, 94110, -122.42178, 37.742578
El Amigo Bar, 3355 Mission St, San Francisco, CA, 94110, -122.421575, 37.742862
Thirty Three Hundred Club, 3300 Mission St, San Francisco, CA, 94110, -122.421485, 37.743123


Solution

  • Damn, just got it after 20 minutes looking back and forth...

    Nothing to do with the gem: look at your coordinates:

    Gmaps4Rails.markers = [{"longitude": "37.742956", "latitude": "-122.421695"},
           {"longitude": "37.742668", "latitude": "-122.421735"},
           {"longitude": "37.742578", "latitude": "-122.42178"},
           {"longitude": "37.742862", "latitude": "-122.421575"},
           {"longitude": "37.743123", "latitude": "-122.421485"}]
    

    You put your latitudes in the longitude table and vice-versa.

    Longitude = [-180, 180]

    Latitude = [-90, 90]