How to Reverse Geocode Coordinates in Ruby
Reverse geocoding is the process of converting a location as described by latitude and longitude coordinates to an address or place name that is human-readable. If you or your company offers location-based services, it’s important to have reverse geocoding integrated into your application or system to allow for the best end-user experience. The following API will perform the process for you by converting geographic coordinates into a full street address.
To use the API in Ruby, you will first need to add the client to your Gemfile:
gem 'cloudmersive-validate-api-client', '~> 2.1.6'
Once the client is added, you can call the reverse geocode function by inputting your coordinates into the below example code:
# load the gem
require 'cloudmersive-validate-api-client'
# setup authorization
CloudmersiveValidateApiClient.configure do |config|
# Configure API key authorization: Apikey
config.api_key['Apikey'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
#config.api_key_prefix['Apikey'] = 'Bearer'
endapi_instance = CloudmersiveValidateApiClient::AddressApi.newinput = CloudmersiveValidateApiClient::ReverseGeocodeAddressRequest.new # ReverseGeocodeAddressRequest | Input reverse geocoding requestbegin
#Reverse geocode a lattitude and longitude into an address
result = api_instance.address_reverse_geocode_address(input)
p result
rescue CloudmersiveValidateApiClient::ApiError => e
puts "Exception when calling AddressApi->address_reverse_geocode_address: #{e}"
end
And you’re done! If you need to retrieve an API key, you can do so by registering for a free account on the Cloudmersive website; this will provide 800 monthly calls across our multitude of APIs.