Class: Graticule::Geocoder::Google

Inherits:
Rest show all
Defined in:
lib/graticule/geocoder/google.rb

Overview

First you need a Google Maps API key. You can register for one here: www.google.com/apis/maps/signup.html

gg = Graticule.service(:google).new(MAPS_API_KEY)
location = gg.locate '1600 Amphitheater Pkwy, Mountain View, CA'
p location.coordinates
#=> [37.423111, -122.081783

Constant Summary collapse

PRECISION =
{
  0 => :unknown,      # Unknown location. (Since 2.59)
  1 => :country,      # Country level accuracy. (Since 2.59)
  2 => :state,        # Region (state, province, prefecture, etc.) level accuracy. (Since 2.59)
  3 => :state,        # Sub-region (county, municipality, etc.) level accuracy. (Since 2.59)
  4 => :city,         # Town (city, village) level accuracy. (Since 2.59)
  5 => :zip,          # Post code (zip code) level accuracy. (Since 2.59)
  6 => :street,       # Street level accuracy. (Since 2.59)
  7 => :street,       # Intersection level accuracy. (Since 2.59)
  8 => :address       # Address level accuracy. (Since 2.59)
}

Constants inherited from Base

Base::USER_AGENT

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Google

Creates a new GoogleGeocode that will use Google Maps API key.



30
31
32
33
# File 'lib/graticule/geocoder/google.rb', line 30

def initialize(key)
  @key = key
  @url = URI.parse 'http://maps.google.com/maps/geo'
end

Instance Method Details

#locate(address) ⇒ Object

Locates address returning a Location



36
37
38
# File 'lib/graticule/geocoder/google.rb', line 36

def locate(address)
  get :q => address.is_a?(String) ? address : location_from_params(address).to_s
end