Created
August 31, 2015 19:33
-
-
Save phsacramento/082b53eca7c31cb52ef1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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