Skip to content

Instantly share code, notes, and snippets.

@forrestwilkins
Created February 5, 2015 21:16
Show Gist options
  • Save forrestwilkins/2254846e24bc5da45945 to your computer and use it in GitHub Desktop.
Save forrestwilkins/2254846e24bc5da45945 to your computer and use it in GitHub Desktop.
def current_location
geoip = GeoIP.new('GeoLiteCity.dat').city(self.ip)
if defined? geoip and geoip
self.latitude = geoip.latitude
self.longitude = geoip.longitude
if latitude and longitude
geocoder = Geocoder.search("#{latitude}, #{longitude}").first
if geocoder and geocoder.formatted_address
self.address = geocoder.formatted_address
end
end
end
get_zip if self.zip_code.nil?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment