Skip to content

Instantly share code, notes, and snippets.

@csexton csexton/get-tz.js
Created Aug 11, 2017

Embed
What would you like to do?
get_tz = ()->
lat = $('input[name=lat]').val()
lng = $('input[name=lng]').val()
time = Math.round((new Date().getTime())/1000)
$.ajax(
url:"https://maps.googleapis.com/maps/api/timezone/json?location=#{lat},#{lng}&timestamp=#{time}&sensor=false",
).done((response) ->
if(response.timeZoneId != null)
console.log(response)
alert(response.timeZoneId)
)
defer_tz_updater = null
defer_get_tz = ()->
# Defer the change incase this gets called multiple times quickly
clearTimeout(defer_tz_updater)
defer_tz_updater = setTimeout(get_tz,500)
$('input[name=lat]').change (event)->
defer_get_tz()
$('input[name=lng]').change (event)->
defer_get_tz()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.