Rails geocoder宝石问题 [英] Rails geocoder gem issues

查看:103
本文介绍了Rails geocoder宝石问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用geocoder gem,并且需要为模型编写开始和结束地址,但是我不确定是否可以使用此gem来完成此操作,并且如果可以,我是否可以正确执行此操作。如果这不能用宝石完成,是否有另一个资源可以让我在同一个表单上对两个位置进行地理编码?这是我想要做的一个例子,但它只是传递第二个地址进行geocoded。

I am using the geocoder gem and I need to code a start and end address for a model, however I am not sure if I can accomplish this using this gem and if I can whether I am doing it correctly. If this cannot be done with the gem, is there another resource that will allow me to geocode two locations on the same form? This is an example of what I am trying to do, but it just passes the second address to be geocoded.

geocoded_by :start_address
before_validation :geocode
geocoded_by :delivery_address, :latitude => :end_latitude, :longitude => :end_longitude
before_validation :geocode


推荐答案

继续只是简单的红宝石......如果你这样做:

So what's going on is just simple ruby... if you do this:

class Question
  def ask
    "what would you like?"
  end

  def ask
    "oh hai"
  end
end

Question.new.ask
 => "oh hai"

最后一个方法定义获胜......所以当您声明两个 geocoded_by 方法,第二个是重要的。

The last method definition wins... so when you declare two geocoded_by methods, the 2nd is the one that counts.

我想你将不得不手动地理编码,使用gem

I think you're going to have to manually geocode, using the gem

before_validation :custom_geocoding

def custom_geocoding
  start_result = Geocoder.search(start_address)
  end_result = Geocoder.search(delivery_address)
  # manually assign lat/lng for each result
end

这篇关于Rails geocoder宝石问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆