Awesome Open Source
Awesome Open Source

Build Status Code Climate Gem Version Gem

OfflineGeocoder

A gem for offline reverse geocoding. It uses data from the GeoNames project.

Installation

Add this line to your application's Gemfile:

gem 'offline_geocoder'

And then execute:

$ bundle

Or install it yourself as:

$ gem install offline_geocoder

Usage

require "offline_geocoder"
geocoder = OfflineGeocoder.new
results = geocoder.search(51.5214588, -0.1729636)
p results

The above code will output this:

{:lat=>51.51116, :lon=>-0.18426, :name=>"Bayswater", :admin1=>"England", :admin2=>"Greater London", :cc=>"GB", :country=>"United Kingdom"}

Alternatively, you can use named parameters when searching:

results = geocoder.search(lat: 51.5214588, lon: -0.1729636)

Searching for names or attributes

You can search for names, countries and such. The first result will be returned.

Searches are case sensitive and must match entirely. e.g. "York" will not find "New York", and "Cote dIvoire" will not match "Cote d'Ivoire".

require "offline_geocoder"
geocoder = OfflineGeocoder.new
aus = geocoder.search(name: "Bayswater")
p aus
gb = geocoder.search(name: "Bayswater", country: "United Kingdom")
p gb

The above code will output this:

{:lat=>-37.85, :lon=>145.26667, :name=>"Bayswater", :admin1=>"Victoria", :admin2=>"Knox", :cc=>"AU", :country=>"Australia"}
{:lat=>51.51116, :lon=>-0.18426, :name=>"Bayswater", :admin1=>"England", :admin2=>"Greater London", :cc=>"GB", :country=>"United Kingdom"}

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Contact Me

If you find any bugs or have a problem while using this library, please open an issue in this repo (or a pull request :)).


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Ruby (312,063
Gem (1,238
Offline (802
Geocoding (338
Related Projects