summaryrefslogtreecommitdiff
path: root/StoneIsland/www/js/lib/etc/geo.js
diff options
context:
space:
mode:
Diffstat (limited to 'StoneIsland/www/js/lib/etc/geo.js')
-rwxr-xr-xStoneIsland/www/js/lib/etc/geo.js44
1 files changed, 38 insertions, 6 deletions
diff --git a/StoneIsland/www/js/lib/etc/geo.js b/StoneIsland/www/js/lib/etc/geo.js
index fac34c1e..88521bb1 100755
--- a/StoneIsland/www/js/lib/etc/geo.js
+++ b/StoneIsland/www/js/lib/etc/geo.js
@@ -1,23 +1,49 @@
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 )
- var lng_str = as_degrees( position.coords.longitude || -74.07944 )
+ var lat_str = as_degrees( position.coords.latitude || 40.99167, "N", "S" )
+ var lng_str = as_degrees( position.coords.longitude || -74.07944, "W", "E" )
$(".latlng").html( lat_str + " " + lng_str )
+ geo.done()
}
geo.error = function(error){
- $(".latlng").html( "+40° 58' 90\" -74° 04' 46\"" )
+ $(".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) {
+ function as_degrees (n, pos, neg) {
var s = ""
- if (n >= 0) s += "+"
+ var sig = n >= 0 ? pos : neg
+
s += Math.floor(n) + "° "
n = Math.abs(n)
@@ -31,7 +57,13 @@ var geo = (function(){
n *= 60
nn = Math.floor(n)
if (nn < 10) nn = "0" + nn
- s += nn + '"'
+ s += nn
+
+ n %= 1
+ n *= 10
+ nn = Math.floor(n)
+ s += "." + nn + '\" ' + sig
+
return s
}