I have gotten the entire map to display correctly with no issues. However, the map always loads at coordinates of 0,0
. I know I'm passing the longitude and latitude correctly as well.
Here's the printed json which the gmaps4rails
method receives:
[{"lat":40.7142,"lng":74.0064}]
Below is also the code used in various areas of production...
VIEW
<%= @maps %>
<%= gmaps4rails(@maps) %>
MODEL
acts_as_gmappable :process_geocoding => false, :lat => :lat, :lng => :lng
def lat
40.7142
end
def lng
74.0064
end
CONTROLLER
@maps = Event.find(params[:id]).to_gmaps4rails
I've decided as you'll see in my model to explicitly pass a latitude and longitude. I do have my database setup with columns latitude
and longitude
, however, I'm working with test data at the moment and cannot expect a reliable result. Until then, I'll use the coordinates for New York City, NY.
Here's the outputted Javascript:
Gmaps.map = new Gmaps4RailsGoogle();
Gmaps.load_map = function() {
Gmaps.map.map_options.auto_adjust = true;
Gmaps.map.initialize();
Gmaps.map.markers = [{"lat":40.7142,"lng":74.0064}];
Gmaps.map.markers_conf.do_clustering = true;
Gmaps.map.create_markers();
Gmaps.map.adjustMapToBounds();
Gmaps.map.callback();
};
Gmaps.oldOnload = window.onload;
window.onload = function() { Gmaps.triggerOldOnload(); Gmaps.loadMaps(); };
I do get an error Uncaught TypeError: Object #<Gmaps4RailsGoogle> has no method create_markers
.
Also, here is a picture of the issue (notice the printed json above the map as done in the view code above):
I fixed the issue by using Coffeescript. Before I had manually copied the javascript files because I didn't want to use Coffeescript on my application.
My installation was wrong, use Coffeescript.