geokit / geokit-rails

Official Geokit plugin for Rails/ActiveRecord. Provides location-based goodness for your Rails app. Requires the Geokit gem.
MIT License
1.57k stars 245 forks source link

no implicit conversion of Symbol into Integer #74

Closed tommybernaciak closed 3 years ago

tommybernaciak commented 9 years ago

Methods are not working correctly:

Location.all.within(5, [51.7655426, 19.4570661]) or Location.within(5, [51.7655426, 19.4570661])

gives 'no implicit conversion of Symbol into Integer'

albertobissacco commented 9 years ago

i have the same issue.

langesi commented 8 years ago

I have the same problem

bigfleet commented 8 years ago

I had the same problem and resolved it by removing the 'geocoder' gem from my Gemfile (preferring the geocoding behavior available in this gem.) Those affected may wish to include their Gemfiles.

bertocq commented 8 years ago

Location.within(5, :origin => @somewhere)

You need to pass the position as a hash, not an array

aashish commented 6 years ago

@bertocq origin attribute is expecting an Array. May be Location.within(5, :origin => [37.792,-122.393]) As per @bigfleet, removing geocoder gem worked for me.

js-seo commented 5 years ago

This issue kept occuring even though the arguments were passed correctly and the geocoder gem was not being used. By inspecting the gem code, I found the issue was caused with the sqlite3 db adapter. In my case, using mysql2 solved the issue.

jjercTK commented 5 years ago

i have the same issue, gonna try switching to postgres

sinscary commented 4 years ago

I am facing this issue with sqlite3. I am not using geocoder gem. Is there any solution?

nnat425 commented 3 years ago

Has anyone figured out a solution yet?

ryankopf commented 3 years ago

Just seconding that I'm having the same problem in a new app, using sqlite3 as well as mentioned above.

ryankopf commented 3 years ago

The issue can be traced back to this change in the sqlite3 ruby adapter - https://github.com/sparklemotion/sqlite3-ruby/commit/e897242724eea8492527742a3f85470b7449b54f

you can fix it by creating an /config/initializers/geokit_fix.rb file that contains an updated version of the add_numeric function removing the symbol :numeric, which was probably an initial best-guess as to what kind of value to provide for the previously unused textrep field, defining the type of text representation to use for the column.

Someone can make a patch for this, however this project hasn't been updated in 3 years so I won't bother right now.


module Geokit
  module Adapters
    class SQLite < Abstract

      def self.add_numeric(name)
        @@connection.create_function name, 1 do |func, *args|
          func.result = yield(*args)
        end
      end

      def self.add_math(name)
        add_numeric name do |*n|
          Math.send name, *n
        end
      end

      class << self
        def load(klass)
          @@connection = klass.connection.raw_connection
          # Define the functions needed
          add_math 'sqrt'
          add_math 'cos'
          add_math 'acos'
          add_math 'sin'

          add_numeric('pow') { |n, m| n**m }
          add_numeric('radians') { |n| n * Math::PI / 180 }
          add_numeric('least') { |*args| args.min }
        end
      end

      def sphere_distance_sql(lat, lng, multiplier)
        %|
          (CASE WHEN #{qualified_lat_column_name} IS NULL OR #{qualified_lng_column_name} IS NULL THEN NULL ELSE
          (ACOS(least(1,COS(#{lat})*COS(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*COS(RADIANS(#{qualified_lng_column_name}))+
          COS(#{lat})*SIN(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*SIN(RADIANS(#{qualified_lng_column_name}))+
          SIN(#{lat})*SIN(RADIANS(#{qualified_lat_column_name}))))*#{multiplier})
          END)
         |
      end

      def flat_distance_sql(origin, lat_degree_units, lng_degree_units)
        %|
          (CASE WHEN #{qualified_lat_column_name} IS NULL OR #{qualified_lng_column_name} IS NULL THEN NULL ELSE
          SQRT(POW(#{lat_degree_units}*(#{origin.lat}-#{qualified_lat_column_name}),2)+
          POW(#{lng_degree_units}*(#{origin.lng}-#{qualified_lng_column_name}),2))
          END)
         |
      end

    end
  end
end
ryankopf commented 3 years ago

Closing this as I believe it has been fixed in a recent update. If anyone is still having this problem please submit a new issue.