Geokit-rails: distance queries for Active Record

"Find stores within 10 kilometres of this address" was a common feature request long before every phone had GPS. Geokit-rails was the go-to plugin for it in the Rails 2 years, and unlike many of its contemporaries it is still released.
Two gems, two jobs
Geokit comes in two parts:
- geokit, a plain Ruby gem for geocoding (turning addresses into coordinates and back) through pluggable providers, and for distance and heading calculations between points;
- geokit-rails, which brings those capabilities to Active Record models and controllers.
In a model, acts_as_mappable expects latitude and longitude columns and adds distance-aware queries:
class Store < ApplicationRecord
acts_as_mappable default_units: :kms,
lat_column_name: :lat,
lng_column_name: :lng
end
Store.within(10, origin: [48.8566, 2.3522]).by_distance(origin: [48.8566, 2.3522])
The distance calculation is done in SQL, using formulas adapted to the database adapter, so filtering and sorting happen in the database rather than in Ruby. Geokit-rails can also geocode an address automatically before validation, and offers a controller helper that geocodes the visitor's IP address and stores the result in the session, which was a popular way to pre-select a nearby location.
History and status
The original plugin was installed into vendor/plugins and covered Rails 2. When Rails 3 arrived, a separate port called geokit-rails3 filled the gap for a while; the main gem's 2.x series later took over Rails 3 and newer versions.
According to RubyGems.org, geokit-rails 2.5.2 was released in October 2026, after a gap of more than three years since 2.5.0 (January 2023). It declares a dependency on rails >= 3.0 with no upper bound, so the gemspec alone does not tell you which recent Rails versions are actually tested; check the project's CI configuration before relying on it for Rails 8. The core geokit gem was last released as 1.14.0 in January 2023.
In short: maintained, but at a slow pace. It is a reasonable dependency for an application that already uses it; for new work, compare it with the alternatives below.
Geocoding providers change
Whatever library you use, the geocoding service behind it matters more than the gem. Providers change their terms, pricing, rate limits and API keys over the years, and some that were popular in 2010 no longer exist in the same form. Before relying on geocoding in production:
- read the provider's terms, especially about caching and displaying results on maps from other vendors;
- store the coordinates you obtain, rather than geocoding the same address repeatedly;
- geocode in a background job, with retries and rate limiting, instead of during a web request;
- keep IP-based location as a hint only, since it is often imprecise.
Alternatives
Geocoder
Geocoder (1.8.6, September 2025) covers similar ground: forward and reverse geocoding with many lookup services, IP geolocation, and Active Record scopes such as near for distance queries. It is widely used, well documented, and supports a large number of providers. For a new application that needs geocoding plus simple radius searches, it is usually the first gem to look at.
PostGIS
If location is central to your application (polygons, delivery zones, routes, many points), use the database. PostgreSQL with the PostGIS extension stores geometries and geographies natively, indexes them with GiST indexes, and answers queries such as "within this polygon" or "nearest 20 points" efficiently. In Rails, the activerecord-postgis-adapter and the RGeo gems provide the integration. The adapter's releases track specific Rails versions closely (its 11.1 series targets Active Record 8.1), so upgrade them together.
Plain SQL
For a handful of radius searches on a modest table, a bounding-box filter on indexed latitude and longitude columns followed by a haversine distance calculation in SQL works without any gem. It is worth knowing how the libraries do it, if only to debug them.
For a side-by-side look at these options applied to a real feature, see Geocoder, Geokit and PostGIS compared for a listings search, which includes a worked example with a radius scope and a background geocoding job.
Which to choose
| Situation | Suggestion |
|---|---|
| Existing app on geokit-rails | Keep it; verify it under your Rails version's tests before upgrading |
| New app, geocoding and radius search | Geocoder |
| Location-heavy app, shapes and spatial indexes | PostGIS with activerecord-postgis-adapter |
| A few distance queries | Bounding box plus SQL formula |
For other Rails 2 and 3 era plugins and their status, see the plugin histories.
Category guidesGeocoding and location search
Geocoder, geokit-rails and PostGIS compared, with provider limits and a radius-search example.
Category guidesSearch
Filtering versus full-text search in Rails: Ransack for filter forms, pg_search for PostgreSQL full-text search, and Searchkick, Meilisearch or Thinking Sphinx for a dedicated search engine.
Plugin historiesacts_as_list
How acts_as_list keeps Active Record rows in order, its history since it left Rails core in Rails 2.0, its status in 2026, and alternatives such as positioning and ranked-model.