Reputation: 2453
I'm trying to use the Gmaps4Rails gem to display a number of markers using their lat / long coordinates.
I have a Locations model with two attributes i.e., 'latitude' and 'longitude'. In my controller, I have the following method:
def display
@locations = Location.all
@hash = Gmaps4rails.build_markers(@locations) do |location, marker|
marker.lat location.latitude
marker.lng location.longitude
end
p @hash.inspect
end
When I look in the logs, the hash with all of the Location objects' lat & long coordinates appears to be correct.
In the view, I have the following:
<div style='width: 800px;'>
<div id="map" style='width: 1200px; height: 740px;'></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();
});
</script>
When I load the view, I see the following but when I zoom in or out, the background becomes opaque.
Any thoughts?
Upvotes: 0
Views: 367
Reputation: 115521
As mentioned in comment, google maps crashes when coordinates are null.
You need to create a scope on your model yo only fetch valid geocoded objects.
Upvotes: 1