Reverse Geocode API - Ruby Gem

Reverse Geocode is a simple tool for getting the location of a set of coordinates. Only supports USA and Canada Coordinates. It returns the city, state, and more.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_reversegeocode'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_reversegeocode

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_reversegeocode'

# Initialize the client
client = APIVerve::Reversegeocode::Client.new(api_key: "YOUR_API_KEY")

# Make a request
response = client.execute({
  lat: 40.714224,
  lon: -73.961452
})

# Print the response
puts response

Error Handling

begin
  response = client.execute({ lat: 40.714224, lon: -73.961452 })
  puts response["data"]
rescue APIVerve::Reversegeocode::ValidationError => e
  puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Reversegeocode::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
end

Debug Mode

# Enable debug logging
client = APIVerve::Reversegeocode::Client.new(
  api_key: "YOUR_API_KEY",
  debug: true
)

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "zipcode": "11211",
    "state_abbr": "NY",
    "city": "Brooklyn",
    "state": "New York",
    "distance": 0.6501757300758664,
    "latitudeClosest": "40.712090",
    "longitudeClosest": "-73.95427",
    "countryCode": "US",
    "latitude": 40.714224,
    "longitude": -73.961452,
    "estimatedCity": true,
    "nearestCities": [
      "Brooklyn",
      "Brooklyn Park",
      "East Brooklyn",
      "Brooklyn Center",
      "Brooklyn Heights"
    ]
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.