Skip to content
Roderick Monje edited this page Nov 14, 2021 · 3 revisions

GoogleMapsGeocoder is a simple plain-old Ruby object initialized with an address:

chez_barack = GoogleMapsGeocoder.new '1600 Pennsylvania DC'

Upon initialization, GoogleMapsGeocoder:

  1. requests the Google Maps API to geocode the given address
  2. parses the results
  3. makes the results available via standard getters

For example, to 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"

For more information, review the gem's unit test, which can also be run via:

bundle ex rspec -f d
Clone this wiki locally