Skip to content

Instantly share code, notes, and snippets.

@alixaxel
Created July 18, 2014 15:40
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 alixaxel/6d9012cf38dcc15345cd to your computer and use it in GitHub Desktop.
Save alixaxel/6d9012cf38dcc15345cd to your computer and use it in GitHub Desktop.
var alphabet = 'ABCDEFGHJKMNPQRVWXY0123456789';
var base = alphabet.length;
function calculate_tt(lat, lon) {
lat += 90.0;
lon += 180.0;
lat *= 10000.0;
lon *= 10000.0;
lat = Math.floor(lat);
lon = Math.floor(lon);
var p = lat * 3600000.0 + lon;
var tt_num = p * base;
var c = 0;
for ( i = 1; i < 10; ++i ) {
c += ( p % base ) * i;
p = Math.floor( p / base );
}
c %= 29;
tt_num += c;
tt_num = Math.floor(tt_num);
var tt = "";
for ( i = 0; i < 10; ++i ) {
d = tt_num % base;
if ( ( i == 4 ) || ( i == 7 ) ) {
tt = " " + tt;
}
tt = alphabet.charAt(d) + tt;
tt_num = Math.floor( tt_num / base );
}
return tt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment