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

Rails, google maps for rails(gmaps4rails) - marker list


Is it possible to make marker list with gmaps4rails similiar to google maps?

I want to make something like that:

http://maps.google.pl/maps?hl=pl&biw=1280&bih=658&q=pharmacy&gs_sm=e&gs_upl=462l1804l0l2192l8l7l0l0l0l0l266l1104l0.4.2l6l0&um=1&ie=UTF-8&sa=N&tab=wl

I have found option to declare list:

https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Markers

But I don't know how to add to each marker upcase character(ie A, B, C).


Solution

  • It cannot be direct. You should:

    • Create a mapping between your set of objects and a letter (one id => one letter).

    • use this mapping to create the proper text in the list

    • import a list of markers with letters and pick the right one according to your mapping


    Edit:

    In your model:

     attr_accessor :number
    
     def gmaps4rails_sidebar
       "#{number}: whatever text you need"
     end
    
     def gmaps4rails_marker_picture
       # set picture depending on number
     end
    

    In your controller:

     @users = User.all
     @users.each_with_index do |user,index|
       user.number = index
     end
     @json = @users.to_gmaps4rails