我根据README设置了所有内容,这是我的模型
class Building
include Gmaps4rails::ActsAsGmappable
include Mongoid::Document
include Geocoder::Model::Mongoid
acts_as_gmappable :lat => 'location[0]', :lng => 'location[1]',
:address => "address", :normalized_address => "full_address",
:msg => "Sorry, not even Google could figure out where that is"
field :gmaps, :type => Boolean
field :address, :type => String, :default => ""
field :city, :type => String, :default => ""
field :province, :type => String, :default => ""
field :country, :type => String, :default => ""
field :postal_code, :type => Integer
field :location, :type => Array, spacial: {lat: :latitude, lng: :longitude, return_array: true }
## Building index
index({location: "2d"})
def full_address
"#{address}, #{city}, #{province}, #{country}, #{postal_code}"
end
def gmaps4rails_address
full_address
end
end
控制器
@hash = Gmaps4rails.build_markers(@building) do |building, marker|
marker.lat building.location[0]
marker.lng building.location[1]
end
和视图
= gmaps4rails( "markers" => { "data" => @hash.to_json, "options" => { "draggable" => true }})
当我访问控件时,给我“未初始化的常量Gmaps4rails :: ActsAsGmappable”