TypeError:没有使用geokit-rails将Symbol隐式转换为Integer进行搜索

时间:2014-08-08 13:29:11

标签: ruby-on-rails ruby activerecord geocoding geokit

我已经使用地理编码器安装了geokit-rails gem,并使用正确的API密钥和设置正确加载了我的配置。我已经正确构造了具有浮点值的latlng列编码的ActiveRecord对象。现在我试图简单地搜索距离给定原点100公里范围内的场地(Venue activerecord):

Venue.within(100, origin: Geokit::LatLng.new(-27.12,124.2141))

然而我一直收到错误:

TypeError: no implicit conversion of Symbol into Integer
    from /usr/local/lib/ruby/gems/2.1.0/gems/geocoder-1.2.3/lib/geocoder/sql.rb:14:in `[]'
    from /usr/local/lib/ruby/gems/2.1.0/gems/geocoder-1.2.3/lib/geocoder/sql.rb:14:in `full_distance'
    from /usr/local/lib/ruby/gems/2.1.0/gems/geocoder-1.2.3/lib/geocoder/stores/active_record.rb:157:in `distance_sql'
    from /usr/local/lib/ruby/gems/2.1.0/gems/geokit-rails-2.0.1/lib/geokit-rails/acts_as_mappable.rb:228:in `distance_conditions'
    from /usr/local/lib/ruby/gems/2.1.0/gems/geokit-rails-2.0.1/lib/geokit-rails/acts_as_mappable.rb:108:in `within'
    from (irb):46
    from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.0/lib/rails/commands/console.rb:90:in `start'
    from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.0/lib/rails/commands/console.rb:9:in `start'
    from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:69:in `console'
    from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.0/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

有人会帮忙吗?

1 个答案:

答案 0 :(得分:0)

你可以直接在Lat&amp; Long的方法中使用Geokit - from docs。 F.e:     :origin => [37.792,-122.393]. 在您的情况下Venue.within(100, origin: [-27.12,124.2141])

为什么要使用Geokit :: LatLng.new?