Skip to content

Instantly share code, notes, and snippets.

@csexton
Created August 11, 2017 20:25
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 csexton/5bd8d7634e51c026f3d16507bcdd51c2 to your computer and use it in GitHub Desktop.
Save csexton/5bd8d7634e51c026f3d16507bcdd51c2 to your computer and use it in GitHub Desktop.
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