diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-05-10 17:15:14 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-05-10 17:15:14 +0200 |
| commit | 2fb2e09bb24340a7cc33ae30037f45125791131c (patch) | |
| tree | 45afccf7b9455ab48f7725a24bae5c28ad02ca9e /StoneIsland/platforms/android/assets/www/js/lib/etc/geo.js | |
| parent | 6196541cf993d5a1a4b8b7f511bf7daf8f849608 (diff) | |
androidz
Diffstat (limited to 'StoneIsland/platforms/android/assets/www/js/lib/etc/geo.js')
| -rwxr-xr-x | StoneIsland/platforms/android/assets/www/js/lib/etc/geo.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/StoneIsland/platforms/android/assets/www/js/lib/etc/geo.js b/StoneIsland/platforms/android/assets/www/js/lib/etc/geo.js new file mode 100755 index 00000000..22899141 --- /dev/null +++ b/StoneIsland/platforms/android/assets/www/js/lib/etc/geo.js @@ -0,0 +1,71 @@ +var geo = (function(){ + var geo = {} + + var polling = false, fetching = false, poll_timeout = null + + geo.fetch = function(){ + fetching = true + navigator.geolocation.getCurrentPosition(geo.success, geo.error, {timeout: 15000}) + } + + geo.success = function(position){ + var lat_str = as_degrees( position.coords.latitude || 40.99167, "N", "S" ) + var lng_str = as_degrees( position.coords.longitude || -74.07944, "E", "W" ) + $(".latlng").html( lat_str + " " + lng_str ) + geo.done() + } + + geo.error = function(error){ + $(".latlng").html( "+40° 58' 90.9\" N 74° 04' 46.3\" W" ) + geo.done() + } + + geo.done = function(){ + fetching = false + if (polling) { + clearTimeout( poll_timeout ) + poll_timeout = setTimeout(geo.fetch, 15000) + } + } + + geo.start_polling = function(){ + polling = true + if (! fetching) { + geo.fetch() + } + } + + geo.stop_polling = function(){ + polling = false + clearTimeout(poll_timeout) + } + + function as_degrees (n, pos, neg) { + var s = "" + var sig = n >= 0 ? pos : neg + + n = Math.abs(n) + s += Math.floor(n) + "° " + + n %= 1 + n *= 60 + nn = Math.floor(n) + if (nn < 10) nn = "0" + nn + s += nn + "' " + + n %= 1 + n *= 60 + nn = Math.floor(n) + if (nn < 10) nn = "0" + nn + s += nn + + n %= 1 + n *= 10 + nn = Math.floor(n) + s += "." + nn + '\" ' + sig + + return s + } + + return geo +})()
\ No newline at end of file |
