Google::Geo

A simple, elegant library for getting geocoding information from Google Maps. Very much inspired by the google-geocode gem, but completely dependency free!

Examples

geo = Google::Geo.new API_KEY addresses = geo.locate ‘1600 Amphitheatre Parkway, Mountain View, CA’ addresses.size # 1, :locate always returns an Array address = addresses.first address.country # ‘US’ address.city # ‘Mountain View’ address.full_address # ‘1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA’ address.query # ‘1600 Amphitheatre Parkway, Mountain View, CA’ address.accuracy # 8 address.coordinates # [-122.084143, 37.421972, 0.0]

In the case of sufficiently vague queries, Google::Geo will return more than one:

addresses = geo.locate ‘hell’ addresses.size # 2 addresses.map { |a| a.state } # [‘PA’, ‘NC’]

You can reverse geocode:

address = geo.locate(33.998671, -118.075926).first address.city # => Pico Rivera address.state # => CA address.zip # => 90660 address.country # => US address.full_address # => 4952-4958 Tobias Ave, Pico Rivera, CA 90660, USA

You can optionally enable the ability to get street view embed HTML for an Address:

require “google/geo/address/street_view” address.street_view_html :id => :street_view, :style => “width:640px; height:480px”

Options

If you need to get the results in another language, you can set it like so:

geo = Google::Geo.new API_KEY, “de” geo.language = “en”

The language code can be anything listed on http://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1.

Contributors

License

© 2007-2009 Seth Thomas Rasmussen and released under the WTFPL. See the LICENSE file for details.