2

首先,这颗宝石看起来棒极了——感谢@apneadiving。我希望有一天能够做出贡献——一旦我弄清楚如何正确使用它:-\

一个可怕的新手问题,我担心......而且我知道我应该能够仅仅基于 Ruby 主义来解决它......但我没能弄清楚我做错了什么......

我无法克服这个错误:

NoMethodError (undefined method `gmaps4rails_options' for <WaterSupply>...

我已经探索了许多不同的方式来编码坐标,但错误——我相信——只是在acts_as_gmappable某种程度上不“工作”。我的模型是这样的:

class WaterSupply
  include Gmaps4rails::ActsAsGmappable
  include MongoMapper::Document

  acts_as_gmappable :process_geocoding => false

  ensure_index [[:loc, '2d']]

  def initialize
    puts Gmaps4rails::ActsAsGmappable.inspect
    puts "*"*50
  end

  key :name, String, :required => true

  # TODO break this address/geo stuff out into a separate Location class
  key :loc, GeoPoint, :default => [40.34962381,-74.75102367]
  key :gmaps, Boolean
  key :address, String
  key :city, String
  key :zip, String
  key :country, String

  def gmaps4rails_address
      "#{self.address}, #{self.zip} #{self.city}, #{self.country}"
  end
end

任何帮助,将不胜感激。我可以看到一张空白地图,没有任何模型实例数据:-p

一旦我开始工作,我将添加一篇博客文章或一个 wiki 页面以使用 MongoMapper 和 Gmaps4Rails!

4

1 回答 1

2

我在这里有一个使用 MongoMapper 的示例

模型类如下所示:

class WaterSupply
  include MongoMapper::Document
  include Gmaps4rails::ActsAsGmappable
  acts_as_gmappable :lat => 'latitude', :lon => 'longitude', :process_geocoding => true,
                    :check_process => :prevent_geocoding,
                    :address => "address", :normalized_address => "address"
                    #:msg => "Sorry, not even Google could figure out where that is"

  key :name, String
  key :address, String
  key :street, String
  key :zip, String
  key :city, String
  key :state, String
  key :country, String
  key :latitude, Float
  key :longitude, Float
  key :gps, GeoPoint  # lat, lon; e.g., [40.34962381,-74.75102367]
  key :gmaps, Boolean

  ensure_index [[:gps, "2d"]]

  before_save :store_geo

  def store_geo
    self.gps = [self.latitude, self.longitude]
  end

  def prevent_geocoding
    address.blank? || (!latitude.blank? && !longitude.blank?)
  end
  def gmaps4rails_address
    "#{self.street}, #{self.city}, #{self.state} #{self.zip} #{self.country}"
  end
  #def gmaps4rails_infowindow
  #  "#{self.name} #{self.gps}"
  #end
  def gmaps4rails_title
    "#{self.name}"
  end

  def gmaps4rails_sidebar
    "#{self.name} #{self.gps}"
  end

end
于 2011-10-03T02:37:04.153 回答