Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 vendor
Octocat-spinner-32 .gitignore
Octocat-spinner-32 CHANGELOG
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Manifest
Octocat-spinner-32 README.textile
Octocat-spinner-32 Rakefile
Octocat-spinner-32 google-geo.gemspec
README.textile

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

require ‘rubygems’ require ‘google/gem’ 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:

geo = Google::Geo.new API_KEY location = geo.reverse_locate(:lat => 33.998671, :lon => -118.075926).first location.city # => Pico Rivera location.state # => CA location.zip # => 90660 location.country # => US location.full_address # => 4952-4958 Tobias Ave, Pico Rivera, CA 90660, USA

You can locate street view

geo = Google::Geo.new API_KEY address = geo.locate(‘1600 Amphitheatre Parkway, Mountain View, CA’).first address.street_view # => Returns an HTML Flash Embed Tag to display street view geo = Google::Geo.new API_KEY location = geo.reverse_locate(:lat => 33.998671, :lon => -118.075926).first location.street_view # => Returns street view for location

Options

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

geo = Google::Geo.new API_KEY geo.language = ‘de’

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

Contributors

License

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

Something went wrong with that request. Please try again.