Geocodable
Geocodable is a UK geocoding Ruby gem powered by Geocodable.io.
Using open data released by Royal Mail, Ordnance
Survey and the Office for National Statistics, Geocodable can geocode UK mainland postcodes, streets and place names.
Installation
Add this line to your application's Gemfile:
gem 'geocodable'
And then execute:
$ bundle
Or install it yourself as:
$ gem install geocodable
Usage
You'll need an API key to get started and one can be registered for free at
https://account.geocodable.io/signup.
Once you've registered an API key, the geocode
method can be used to query
the API:
require 'geocodable'
Geocodable.api_key = 'YOUR-API-KEY'
Geocodable.geocode('London, UK')
The results will be returned in a Ruby hash:
{
found: 1,
results: [
{
location: {
latitude: 51.517124,
longitude: -0.106196
},
address_components: [
{ type: "city", name: "London" },
{ type: "country", name: "United Kingdom" },
{ type: "country_code", name: "UK" }
]
}
]
}
Exceptions
Geocodable will raise an exception if the response from the server is anything
other that a successful HTTP 2XX response.
begin
Geocodable.geocode('London, UK')
rescue Geocodable::InvalidRequestError => e
rescue Geocodable::AuthenticationError => e
rescue Geocodable::AccessDisabledError => e
rescue Geocodable::OverRequestLimitError => e
rescue Geocodable::APIError => e
rescue => e
end
## Requirements
- Ruby 1.9.3 and above. (May work on lower 1.9 versions)
- Gems: faraday, excon, json
Development
RSpec tests can be run with: bundle exec rspec spec
Contributing
- Fork it ( https://github.com/geocodable/geocodable-ruby/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request