Created
September 24, 2020 19:33
-
-
Save 1dolinski/469ef12a9c18b6bd31dd7ac9cc37c67e to your computer and use it in GitHub Desktop.
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
const googleGeoCode = (city, callback) => { | |
const url = `https://maps.googleapis.com/maps/api/geocode/json`; | |
const data = { | |
address: city, | |
key: googleClientAPIKey | |
} | |
$.ajax({ url: url, data: data, success: callback, dataType: 'json' }); | |
} | |
const googleTimeZone = (location, callback) => { | |
var epochDate = new Date(); | |
var timestamp = epochDate.getTime() / 1000 | |
const url = `https://maps.googleapis.com/maps/api/timezone/json`; | |
const data = { | |
location: Object.values(location).join(','), | |
timestamp: timestamp, | |
key: googleClientAPIKey | |
} | |
$.ajax({ url: url, data: data, success: callback, dataType: 'json' }); | |
} | |
if(window.google){ | |
initMap(); | |
} else{ | |
$.ajax(ajaxAddress, { | |
crossDomain: true, | |
dataType: 'script' | |
}); | |
} | |
const timeZoneSelector = () => { | |
timeZoneSearch.focusout(() => { | |
const val = timeZoneSearch.val(); | |
const noTimeZone = (val === '' || val === undefined || val === null); | |
if (noTimeZone) { return }; | |
googleGeoCode(val, geoCodeData => { | |
const geocodeLocation = geoCodeData.results[0].geometry.location; | |
googleTimeZone(geocodeLocation, timezoneData => { | |
timeZoneLink.text(timezoneData.timeZoneId); // set label | |
timeZoneValue.val(timezoneData.timeZoneId); // set form field | |
}) | |
}); | |
}) | |
timeZoneSearch.keypress(function(event){ | |
var keycode = (event.keyCode ? event.keyCode : event.which); | |
if (keycode == '13') { | |
$(this).blur(); | |
event.preventDefault(); | |
event.stopPropagation(); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment