Class: Graticule::Geocoder::Google

Inherits:
Base
  • Object
show all
Defined in:
lib/graticule/geocoder/google.rb

Overview

gg = Graticule.service(:google).new

location = gg.locate '1600 Amphitheater Pkwy, Mountain View, CA'
p location.coordinates
#=> [37.423111, -122.081783

If you have a Google business account, initialize with:

gg = Graticule.service(:google).new(MAPS_API_KEY, MAPS_CLIENT_ID)

Defined Under Namespace

Classes: Response, Result

Constant Summary

Constants inherited from Base

Base::USER_AGENT

Instance Method Summary collapse

Constructor Details

#initialize(key = nil, client_id = nil) ⇒ Google



17
18
19
20
21
# File 'lib/graticule/geocoder/google.rb', line 17

def initialize(key=nil, client_id=nil)
  @key = key
  @client_id = client_id
  @url = URI.parse 'https://maps.googleapis.com/maps/api/geocode/json'
end

Instance Method Details

#locate(address) ⇒ Object

Locates address returning a Location



24
25
26
# File 'lib/graticule/geocoder/google.rb', line 24

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