Skip to content

Instantly share code, notes, and snippets.

@chris-roerig
Created April 25, 2016 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-roerig/f0a5e12ebc76aac5c31bbcac2a6830d8 to your computer and use it in GitHub Desktop.
Save chris-roerig/f0a5e12ebc76aac5c31bbcac2a6830d8 to your computer and use it in GitHub Desktop.
Returns the time zone id for a given set of coordinates
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