Skip to content

Instantly share code, notes, and snippets.

@eduzera
Forked from phsacramento/Geolocation With Rails
Last active August 31, 2015 21:05
Show Gist options
  • Save eduzera/009c3753eb4217c90150 to your computer and use it in GitHub Desktop.
Save eduzera/009c3753eb4217c90150 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