如何使用 google-maps-for-rails 将颜色参数传递给 google maps api?我想根据一个值设置 Controller 内每个标记的颜色,所以有些是红色,有些是黄色,有些是绿色。我相信它是 Symbol 中的 icon 属性,查看:
https://developers.google.com/maps/documentation/javascript/reference#MarkerOptions
另外,我想在标记内有一个 1-99 的数字,这可能吗?到目前为止,我有这个。
@json = Device.all.to_gmaps4rails do |device, marker|
end
我已经为此苦苦挣扎了好几天,任何帮助将不胜感激。
最佳答案
您应该简单地利用谷歌的图表 api。
例如,以下是一个标记:
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
关于ruby-on-rails - 在 Rails 中使用 google-maps-for-rails gem 时设置标记颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12691330/