talira

Geocoder

Complete geocoding solution for Ruby

open sourceMITself-hostablefree

Geocoder turns addresses into coordinates, coordinates into addresses and IP addresses into locations, through more than 40 services, among them Google's Geocoding API and Google Places API, Nominatim, Mapbox, HERE, Bing, Esri, OpenCage, Geoapify and many national and IP lookup APIs, or a local MaxMind GeoLite2 database. Added to an ActiveRecord or Mongoid model with geocoded_by or reverse_geocoded_by, it fills latitude and longitude on save and adds near and within_bounding_box scopes, distances and bearings for MySQL, PostgreSQL and SQLite. It caches results in Redis or any key-value store, adds a location method to Rack requests, has a test lookup for specs and ships a geocode command. Alex Reisner first released it in 2009.

Problems it solves

  • turn the street addresses in my database into latitude and longitude
  • find all stores within 20 miles of a customer's location in my Rails app
  • show the nearest locations to the visitor based on their IP address
  • get a readable address back from GPS coordinates a phone app sent
  • switch geocoding providers without rewriting my code when one gets expensive
  • cache geocoding API responses so I don't burn through my daily quota
  • geocode thousands of existing records in batches without hitting rate limits
  • use different geocoding services for addresses in different countries
  • work out the distance and compass bearing between two points in Ruby
  • look up an IP's city offline from a downloaded MaxMind database
  • stop my specs making real network calls to the geocoding API
  • geocode an address from the terminal to check what a provider returns
  • sort search results by distance from a postcode

Features

  • forward and reverse geocoding
  • IP address geolocation, including Rack request.location and safe_location
  • more than 40 street address and IP lookup services, plus local MaxMind GeoLite2 and IP2Location LITE files
  • geocoded_by and reverse_geocoded_by for ActiveRecord and Mongoid models
  • near, within_bounding_box and nearbys scopes with distance and bearing
  • distance, bearing and geographic center calculations
  • result caching in Redis, Rails.cache or any key-value store
  • per-lookup configuration and per-model lookup selection
  • rake geocode:all with batches, sleep and limit options
  • test lookup that returns stubbed results
View 2 more
  • geocode command-line tool
  • works outside Rails with ActiveRecord, e.g. Sinatra

Limitations

  • Doesn't hold its own geocoding data: every lookup goes to an outside service you configure (or a local MaxMind file for IPs), and accuracy depends on it1
  • No radius or distance queries for MongoDB models: use MongoDB's own geospatial queries1

Capabilities

Has an APIplan not known
Has a command line toolplan not known

Alternatives

The same job

These do what Geocoder does.

  1. Nominatim Open-source geocoding with OpenStreetMap data
  2. OpenCage Forward and reverse geocoding API built on open data, at a flat monthly fee
  3. Smarty Address verification, autocomplete and geocoding APIs (formerly SmartyStreets)

Compare Geocoder with the top 3