如何使用gmaps4rails在Mongoid数组中存储地理编码

时间:2012-10-23 00:29:34

标签: ruby-on-rails mongoid gmaps4rails

我能够使用mongoid的gmaps4rails中的基本地图显示功能,这很棒,但我没有更多高级功能。我想我缺少一些基础知识并寻找指导。 我能够使用基本地理编码来处理名为:latitude:longitude和:gmaps的字段,但是当我尝试使用数组时,正如自述文件所示,我无处可去。我已经阅读了维基中的Mongoid技巧,但没有用。

有人能指出我正确的方向吗?

更新; 由于我没有得到任何回复,这里有一些代码示例,

模特

工作;

class Account
  include Mongoid::Document
  include Gmaps4rails::ActsAsGmappable
  acts_as_gmappable

  field :account_no
  field :owner_name
  field :address
  field :latitude,  :type => Float
  field :longitude, :type => Float
  field :gmaps,     :type => Boolean

  def gmaps4rails_address
    "#{self.address}"
  end

end 

不工作

 class Account
  include Mongoid::Document
  include Gmaps4rails::ActsAsGmappable
  acts_as_gmappable :position => :location

  field :account_no
  field :owner_name
  field :address
  field :location, :type => Array

  def gmaps4rails_address
  "#{self.address}"
  end

end 

根据gmaps4rails自述文件中的代码段,这应该可以将地址编码到位置数组中,但是我收到此错误

NoMethodError: undefined method `gmaps' for #<Account:0x007fc47d051ba0>

1 个答案:

答案 0 :(得分:1)

正如here所解释的那样,gmaps是一个布尔值,其目的是防止对同一地址进行多重地理编码。

因此该字段是必要的,除非您明确说明(参见相同的文档)