Gmaps4rails displays location based on latitude and longitude

I am using gmaps4rails with Rails 3.0.9. I would like to add a marker based on the latitude and longitude coordinates to the map, but I cannot figure out how to do this. I managed to use the map only with andress. Thanks.

The code I'm using is:

application / models / location.rb

class Location < ActiveRecord::Base acts_as_gmappable :process_geocoding => false def gmaps4rails_address "#{self.latitude}, #{self.longitude}" end end 

application / controllers / locations_controller.rb

 def index @json = Location.first.to_gmaps4rails respond_to do |format| format.html end 

app / views / places / index.html.erb

 <%= gmaps4rails(@json) %> 

The location model contains the following fields: latitude, longitude, address .

UPDATE: I found a solution after reading another project wiki about markers. The solution is to use the custom method <%= gmaps %> . I managed to use it like this:

 <%= gmaps({ "map_options" => { "type" => "ROADMAP", "center_longitude" => 28.9, "center_latitude" => 47.03, "zoom" => 12, "auto_adjust" => true}, "markers" => { "data" => @markers } }) %> 

In the controller:

 @markers = '[ {"description": "", "title": "", "sidebar": "", "lng": "28.8701", "lat": "47.0345", "picture": "", "width": "", "height": ""}, {"lng": "28.9", "lat": "47" } ]' 

You can customize these values ​​as you wish.

+4
source share
1 answer

I think you should try gocapoder gem instead of gmaps4rails https://github.com/alexreisner/geocoder http://www.rubygeocoder.com/

I think this is much better than gmaps4rails

0
source

All Articles