Skip to content

Instantly share code, notes, and snippets.

@phsacramento
Created August 31, 2015 19:33
Show Gist options
  • Save phsacramento/082b53eca7c31cb52ef1 to your computer and use it in GitHub Desktop.
Save phsacramento/082b53eca7c31cb52ef1 to your computer and use it in GitHub Desktop.
# gem install geocoder
require "geocoder"
class GeocoderService
def initialize(options={})
@street = options[:street]
@neighborhood = options[:neighborhood]
@city = options[:city]
@state = options[:state]
@country = options[:country]
end
def process
build_address
search
end
def search
@result = Geocoder.search(@address)
end
def build_address
@address = [@street, @neighborhood, @city, @state].compact.join(', ')
end
def result
@location = @result.first
end
end
# get result.latitude - float
# get result.longitude - float
# get result.coordinates - array of the above two
# get result.address - string
# get result.city - string
# get result.state - string
# get result.state_code - string
# get result.postal_code - string
# get result.country - string
# get result.country_code - string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment