让 Gmaps4Rails 与 MongoMapper 一起工作

发布于 2024-12-03 04:24:17 字数 1146 浏览 2 评论 0原文

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

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

我无法克服这个错误:

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!

First off, this gem looks awesome -- thanks @apneadiving. I hope to be able to contribute one day -- once I figure out how to use it properly :-\

A horribly newbie question, I fear... and I know I should be able to figure it out based solely on Ruby-isms... But I have failed to figure out what I am doing wrong...

I cannot get past this error:

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

I have explored many different ways to encode the coords, but the error -- I believe -- is simply in the acts_as_gmappable somehow not "working." My model is this:

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

Any help would be appreciated. I can get a blank map to appear, just nothing with any model instance data :-p

Once I get things working, I'll add a blog post or a wiki page for using MongoMapper and Gmaps4Rails!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等待我真够勒 2024-12-10 04:24:17

我有一个使用 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

I got an example working with MongoMapper here

Model class looks like this:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文