alexreisner/geocoder — Issue #171: SQLite3::SQLException: no such column: lon:
Author: marimaf
Created: 2012-02-03 00:19:46+00:00
State: open

I am trying to get results for the following query:

Event.near([params[:lat].to_f, params[:lng].to_f], params[:radius].to_f, unit: :km)

In my model I have:

geocoded_by :address, :latitude => :lat, :longitude => :lng
after_validation :geocode

but I get the following:

ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: lon: SELECT events.*, (69.09332411348201 * ABS(lat - -33.425329) * 0.7071067811865475) + (59.836573914187355 * ABS(lon - -70.604895) * 0.7071067811865475) AS distance, CASE WHEN (lat >= -33.425329 AND lon >= -70.604895) THEN 45.0 WHEN (lat < -33.425329 AND lon >= -70.604895) THEN 135.0 WHEN (lat < -33.425329 AND lon < -70.604895) THEN 225.0 WHEN (lat >= -33.425329 AND lon < -70.604895) THEN 315.0 END AS bearing FROM "events" WHERE (lat BETWEEN -33.714792566221696 AND -33.1358654337783 AND lon BETWEEN -70.95172225903696 AND -70.25806774096304) ORDER BY distance

Please help