Created
April 25, 2016 14:19
-
-
Save chris-roerig/f0a5e12ebc76aac5c31bbcac2a6830d8 to your computer and use it in GitHub Desktop.
Returns the time zone id for a given set of coordinates
This file contains hidden or 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
def timezone_from_coordinates(lat, long) | |
conn = Faraday.new(url: "https://maps.googleapis.com/maps/api/") | |
res = conn.get("timezone/json") do |req| | |
req.params["location"] = "#{lat},#{long}" | |
req.params["timestamp"] = Time.now.to_i | |
req.params["sensor"] = false | |
end | |
data = JSON.parse res.body | |
data["timeZoneId"] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment