简体   繁体   English

Rails GeoCoder gem 的地址错误

[英]Address error with the Rails GeoCoder gem

I am using the GeoCoder gem to lookup lat and longs for locations, and its seems to working fine in the rails code.我正在使用 GeoCoder gem 来查找纬度和经度的位置,它似乎在 rails 代码中运行良好。 However to get each locations lat/long is going to be long winded and take quite a while.然而,要获得每个位置的纬度/经度将是冗长的,并且需要相当长的时间。

Looking through the docs I have seen I can use rake geocode:all CLASS=Location SLEEP=0.25 BATCH=100 to process batches of 100.浏览我看到的文档,我可以使用rake geocode:all CLASS=Location SLEEP=0.25 BATCH=100来处理 100 个批次。

Using this I am running into the following error...使用这个我遇到了以下错误......

NoMethodError: undefined method `address=' for #<Location:0x00007f9cf3d8daf0>
Did you mean?  address1=
               address2=
               address3=
               address4=
               address
               address4
               address2
               address1
               address3
               address3?
               address2?
               address1?
               address4?

Following the docs, I have set up an address method as shown in the Location model below.按照文档,我设置了一个地址方法,如下面的位置 model 所示。

class Location < ApplicationRecord
  geocoded_by :address
    reverse_geocoded_by :latitude, :longitude
    after_validation :geocode, :reverse_geocode

    # searchkick locations: [:location]

    def address
        [name, postcode].compact.join(", ")
    end

    #  def search_data
  #   attributes.merge location: { lat: latitude, lon: longitude }
  # end
end

I have looked through StackOverflow, and spend quite some time on Google trying to work out what is causing this issue, but can't for the life of me get it to work.我查看了 StackOverflow,并在 Google 上花费了相当长的时间试图找出导致此问题的原因,但我终其一生都无法让它发挥作用。

Any one have any pointers, or can see where I am going wrong?任何人都有任何指示,或者可以看到我哪里出错了?

Thanks谢谢

Geocoder expects there to be an:address column in your model with the reverse geocoding.地理编码器希望在您的 model 中使用反向地理编码有一个:地址列。 You can change the default like so:您可以像这样更改默认值:

reverse_geocoded_by :latitude, :longitude, :address
after_validation :reverse_geocode

I would run a migration to add an address column to your table.我将运行迁移以将地址列添加到您的表中。 So the migration can be like:所以迁移可以像:

rails g model model_name address latitude:float longitude:float

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM