Skip to content

Instantly share code, notes, and snippets.

@nateabele
Created September 26, 2013 12:16
Show Gist options
  • Save nateabele/6713348 to your computer and use it in GitHub Desktop.
Save nateabele/6713348 to your computer and use it in GitHub Desktop.
Faking out the Geolocation API
navigator.geolocation.getCurrentPosition = function(callback) {
console.log("Hey look, I'm in London!");
callback({
"timestamp": (new Date()).getTime(),
"coords": {
"speed": null,
"heading": null,
"altitudeAccuracy": null,
"accuracy": 89,
"altitude": null,
"longitude": -0.1257400,
"latitude": 51.5085300
}
});
}
// How to counter the above if you *really* need to use it:
function isSafe() {
try {
var str = navigator.geolocation.getCurrentPosition.toString();
if (str.match(/^function getCurrentPosition\(\)\s*\{\s*\[native code\]/).length === 1) {
return true;
}
} catch (e) {}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment