gpt4 book ai didi

ruby-on-rails - gmaps4rails 根据纬度和经度显示位置

转载 作者:行者123 更新时间:2023-12-04 03:42:56 25 4
gpt4 key购买 nike

我在 Rails 3.0.9 中使用 gmaps4rails。我想在 map 上添加一个基于纬度和经度坐标的标记,但我不知道该怎么做。我设法仅使用带有地址的 map 。谢谢。

我正在使用的代码:

应用程序/模型/location.rb

class Location < ActiveRecord::Base
acts_as_gmappable :process_geocoding => false

def gmaps4rails_address
"#{self.latitude}, #{self.longitude}"
end
end

应用程序/ Controller /locations_controller.rb
def index
@json = Location.first.to_gmaps4rails

respond_to do |format|
format.html
end

应用程序/ View /位置/index.html.erb
<%= gmaps4rails(@json) %>
location模型包含以下字段: latitude, longitude, address .

更新:我在阅读更多关于标记的项目维基后找到了解决方案。解决方法是使用自定义 <%= gmaps %>方法。我设法像这样使用它:
<%= gmaps({
"map_options" => { "type" => "ROADMAP", "center_longitude" => 28.9, "center_latitude" => 47.03, "zoom" => 12, "auto_adjust" => true},
"markers" => { "data" => @markers }
})
%>

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

您可以根据需要自定义这些值。

最佳答案

我认为你应该尝试 geocoder gem 而不是 gmaps4rails
https://github.com/alexreisner/geocoder
http://www.rubygeocoder.com/

我认为它比 gmaps4rails 好得多

关于ruby-on-rails - gmaps4rails 根据纬度和经度显示位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6992400/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com