如何在 Google-Maps-for-Rails 中向标记添加半径?
我正在使用 Google-Maps-for-Rails gem,现在正在尝试显示圆圈。
我的模型“地点”包括:
- 经度
- 纬度
- 半径
- 等
我可以毫无问题地显示标记:
# Controller: @markers = Place.all.to_gmaps4rails
gmaps("markers" => {"data" => @markers})
不幸的是它不包括:radius => .. 我还知道圆圈可以显示为:
gmaps(
"circles" => { "data" => '[
{"longitude": -122.214897, "latitude": 37.772323, "radius":1000000}
]',
})
有没有办法在标记散列中包含半径属性?喜欢:
gmaps("circles" => { "data" => @markers })
可能是这样的:
Place.all.each |place| place.merge!(:radius => 1000) ...
会做,但我认为可能有更好的解决方案
i am using the Google-Maps-for-Rails gem and I am now trying to display circles.
My Model "Place" consists of:
- longitude
- latitude
- radius
- etc
I have no problem to display markers:
# Controller: @markers = Place.all.to_gmaps4rails
gmaps("markers" => {"data" => @markers})
Unfortunately it doens't include :radius => ..
I also know that circles can be displayed like:
gmaps(
"circles" => { "data" => '[
{"longitude": -122.214897, "latitude": 37.772323, "radius":1000000}
]',
})
Is there any way to include the radius attribute in the markers hash ? Like:
gmaps("circles" => { "data" => @markers })
Probably something like:
Place.all.each |place| place.merge!(:radius => 1000) ...
would do, but I think there may be a nicer solution
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
标记和圆圈背后的逻辑确实不同。
在您的控制器中
在您的视图中:
或者,如果您不需要
infowindow
或其他功能,您可以简单地执行以下操作:在您的控制器中
在您的视图中:
The logic behind markers and circles is really different.
In your controller
In your view:
Or if you don't need
infowindow
or other features, you could simply do:In your controller
In your view: