-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetCurrentPos.js
More file actions
39 lines (34 loc) · 1009 Bytes
/
Copy pathgetCurrentPos.js
File metadata and controls
39 lines (34 loc) · 1009 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* Dan Armendariz
* danallan@mit.edu
*
* Place the below snippet above all other JS code to hijack a browser's
* getCurrentPosition() method with something a bit more predictable.
*
*/
navigator.geolocation.getCurrentPosition = function (callback, error_handler, options) {
// retrieve date info for position.timestamp
var d = new Date();
// position object, to pass to callback
var position = {
coords: {
latitude:"42.377334",
longitude:"-71.118228",
accuracy: "100",
},
timestamp: d.getTime()
};
// error object, to pass to error_handler
var error = {
PERMISSION_DENIED:1,
POSITION_UNAVAILABLE:2,
TIMEOUT:3,
code: Math.floor(Math.random()*3)+1,
message: "Dummy message from hijacked getCurrentPosition method"
};
// run callback 95% of the time
if (Math.random() < 0.95)
callback(position);
else
error_handler(error);
};