Created
September 26, 2013 12:16
-
-
Save nateabele/6713348 to your computer and use it in GitHub Desktop.
Faking out the Geolocation API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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