Search code examples
mysqlruby-on-rails-4rails-geocoder

Mysql2::Error:... when calling `near` in geocoder gem


So i have a list of services all geocoded with geogoder gem.

Calling Service.near("London") throws

ActiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near

Service.near("London").to_sql

gives

SELECT services.*, MOD(CAST((ATAN2( ((services.longitude - -4.8824474) / 57.2957795), 
      ((services.latitude - 36.510071) / 57.2957795)) * 57.2957795) + 360 AS decimal), 360) AS bearing 
FROM `services` 
WHERE (services.latitude BETWEEN 36.220607433778305 AND 36.7995345662217 
    AND services.longitude BETWEEN -5.242587667147616 AND -4.522307132852385 
    AND () BETWEEN 0.0 AND 20)  
ORDER BY distance ASC

distance_betweenworks with no problems.

Can anyone advise what i did wrong?

Thanks in advance


Solution

  • At some point i had obviously added and then removed Geokit gem.

    Left in the model was acts_as_mappable

    This caused the SQL syntax to be thrown out.