Skip to content

Instantly share code, notes, and snippets.

@cchandler
Created July 29, 2009 06:50
Show Gist options
  • Save cchandler/157902 to your computer and use it in GitHub Desktop.
Save cchandler/157902 to your computer and use it in GitHub Desktop.
Converting lat/lng to GMT offset
class TimeZoneFinder
def self.find_gmt_offset(lat,lng)
uri = URI.parse("http://ws.geonames.org/timezone?lat=#{lat}&lng=#{lng}")
doc = Hpricot.XML(Net::HTTP.get(uri))
(doc/"geonames"/"timezone"/"gmtOffset").innerHTML.to_f
end
end
offset = TimeZoneFinder.find_gmt_offset(some_lat, some_lng)
timezone = ActiveSupport::TimeZone[offset]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment