GoogleMapsGeocoder
A simple Plain Old Ruby Object wrapper for geocoding with Google Maps, GoogleMapsGeocoder gives you all its geocoding functionality with these advantages:
- easy to use in only one step
- fully documented with complete test coverage
- lightweight at only 10.5 K as a gem (that's just over a tenth the size of Geocoder)
- only a single dependency, the commonly used Rack
Installation
-
Set your Google Maps API key, which Google now requires, as an environment variable:
export GOOGLE_MAPS_API_KEY=[your key] -
Add
GoogleMapsGeocoderto your Gemfile and runbundle:gem 'google_maps_geocoder'
Or try it out in
irbwith:require 'google_maps_geocoder'
Security note
GoogleMapsGeocoder is cryptographically signed. To insure the gem you install hasn’t been tampered with, add my public key as a trusted certificate and then install:
gem cert --add <(curl -Ls https://raw.github.com/FoveaCentral/google_maps_geocoder/master/certs/ivanoblomov.pem)
gem install google_maps_geocoder -P HighSecurityReady to Go in One Step
chez_barack = GoogleMapsGeocoder.new 'White House'Usage
Get the complete, formatted address:
chez_barack.formatted_address
=> "1600 Pennsylvania Avenue Northwest, President's Park, Washington, DC 20500, USA"...standardized name of the city:
chez_barack.city
=> "Washington"...full name of the state or region:
chez_barack.state_long_name
=> "District of Columbia"...standard abbreviation for the state/region:
chez_barack.state_short_name
=> "DC"API
The complete, hopefully self-explanatory, API is:
GoogleMapsGeocoder#cityGoogleMapsGeocoder#country_long_nameGoogleMapsGeocoder#country_short_nameGoogleMapsGeocoder#countyGoogleMapsGeocoder#exact_match?GoogleMapsGeocoder#formatted_addressGoogleMapsGeocoder#formatted_street_addressGoogleMapsGeocoder#latGoogleMapsGeocoder#lngGoogleMapsGeocoder#partial_match?GoogleMapsGeocoder#postal_codeGoogleMapsGeocoder#state_long_nameGoogleMapsGeocoder#state_short_name
For compatibility with Geocoder, the following aliases are also available:
GoogleMapsGeocoder#addressGoogleMapsGeocoder#coordinatesGoogleMapsGeocoder#countryGoogleMapsGeocoder#country_codeGoogleMapsGeocoder#latitudeGoogleMapsGeocoder#longitudeGoogleMapsGeocoder#stateGoogleMapsGeocoder#state_code
Documentation
Complete RDoc documentation is available at RubyDoc.info.
Copyright © 2011-2025 Roderick Monje. See LICENSE.txt for further details.