Skip to content

Instantly share code, notes, and snippets.

@miketaylr
Last active August 29, 2015 13:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miketaylr/8713468 to your computer and use it in GitHub Desktop.
Save miketaylr/8713468 to your computer and use it in GitHub Desktop.
(function() {
var b = navigator.geolocation, i = [], m = {
enableHighAccuracy: true,
maximumAge: 5e3,
timeout: 1e3 * 60 * 2
}, g = null, c = null, n = 0, h = null, a = mqm.Util.isIOS5(), d = function() {
if (b && !c) {
if (a) {
j();
} else {
c = navigator.geolocation.watchPosition(l, k, m);
}
}
}, f = function() {
if (b && c) {
if (a) {
window.clearInterval(c);
} else {
navigator.geolocation.clearWatch(c);
}
c = null;
}
g = null;
i = [];
}, e = function(o) {
$(i).each(function(p, q) {
if (q) {
q(o);
}
});
}, j = function() {
try {
navigator.geolocation.getxCurrentPosition(function(p) {
n++;
l(p);
}, k, m);
} catch (o) {
console.log("error getting position");
}
}, l = function(o) {
var p = {
geoLocation: o
};
g = o;
e(p);
if (a) {
window.setTimeout(j, 3e3);
}
}, k = function(o) {
c = null;
h = {
error: o
};
e(h);
};
(function(o) {
o.lastLocation = function() {
return g;
};
o.addListener = function(q) {
var p = i.push(q) - 1;
d.call(this);
return p;
};
o.removeListener = function(p) {
delete i[p];
if (this.numListeners() == 0) {
f.call(this);
}
};
o.numListeners = function() {
var p = 0;
$(i).each(function(q, r) {
if (r) {
p++;
}
});
return p;
};
o.stop = function() {
f.call(this);
};
o.currentLocation = function() {
var q = $.Deferred();
if (this.lastLocation()) {
q.resolve(this.lastLocation().coords);
} else {
var p = this;
var r = this.addListener(function(s) {
q.resolve(p.lastLocation().coords);
p.removeListener(r);
});
}
return q.promise();
}, o.movedAtLeast = function(s) {
var p = this;
var r = $.Deferred();
var t;
var q = function(u) {
p.currentLocation().done(function(v) {
var w = MQA.Util.distanceBetween({
lat: u.latitude,
lng: u.longitude
}, {
lat: v.latitude,
lng: v.longitude
}, "MI");
if (w >= s) {
r.resolve();
p.removeListener(t);
}
});
};
this.currentLocation().done(function(u) {
t = p.addListener(function() {
q(u);
});
});
return r;
};
})(LocationManager.prototype);
})();
@miketaylr
Copy link
Author

(just a portion, gist didn't like a 33K line file. :()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment