Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby gem for finding timezone of location [closed]

I have a location (city, state), date, and time and I want to convert it to utc, but need to first find the timezone of the location. I've done a little research and everything seems to point to either earthtools or geonames but both webservices appear to be latitude and longitude only. Is there a service or gem or any other way to find the timezone based on this format of location? or how can the location be converted to latitude and longitude?

like image 449
Nick Avatar asked Dec 01 '11 23:12

Nick


1 Answers

You can easily get a latitude and longitude using the google maps geocoding API. There are ruby implementations for the API like GeoKit. Once you have that you can use the timezone gem to easily get the timezone of a latitude and longitude. The gem makes it easy to do time conversions in your timezone as well.

Here is an example using GeoKit and TimeZone.

require 'geokit' require 'timezone'  res = Geokit::Geocoders::GoogleGeocoder.geocode('140 Market St, San Francisco, CA') timezone = Timezone::Zone.new(:latlon => res.ll)  timezone.zone => "America/Los_Angeles" timezone.time Time.now => 2011-12-01 14:02:13 UTC 
like image 139
Pan Thomakos Avatar answered Oct 01 '22 14:10

Pan Thomakos