在Rails中使用google-maps-for-rails gem时设置标记颜色

use*_*541 4 ruby-on-rails ruby-on-rails-3 gmaps4rails

如何使用google-maps-for-rails将颜色参数传递给google maps api?我想根据一个值设置控制器内每个标记的颜色,所以有些是红色,有些是黄色,有些是绿色.我相信它是Symbol中的图标属性,它看着:

https://developers.google.com/maps/documentation/javascript/reference#MarkerOptions

另外,我想在标记内有一个1-99的数字,是否可能?到目前为止,我有这个.

@json = Device.all.to_gmaps4rails do |device, marker|
end
Run Code Online (Sandbox Code Playgroud)

几天来我一直在努力,任何帮助都会受到赞赏.

apn*_*ing 15

你应该只是利用谷歌的图表API.

例如,以下是一个标记:

  • 字母A.
  • 红色: FF0000
  • 黑色文字: 000000

http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=A|FF0000|000000

所以你应该定制你的需求:

@json = Device.all.to_gmaps4rails do |device, marker|
   marker.picture({
     :picture => "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=A|FF0000|000000", # up to you to pass the proper parameters in the url, I guess with a method from device
     :width   => 32,
     :height  => 32
   })
end
Run Code Online (Sandbox Code Playgroud)

  • 这可能在gem的wiki中很有趣 (2认同)