forked from cory/tildefriends
Exposed geolocation API. Now somebody make tildemango.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3294 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
313efbe2d6
commit
f08b564755
@ -6,6 +6,7 @@ var gCredentials;
|
|||||||
var gErrorCount = 0;
|
var gErrorCount = 0;
|
||||||
var gCommandHistory = [];
|
var gCommandHistory = [];
|
||||||
var gSendKeyEvents = false;
|
var gSendKeyEvents = false;
|
||||||
|
var gGeolocatorWatch;
|
||||||
|
|
||||||
var kMaxCommandHistory = 16;
|
var kMaxCommandHistory = 16;
|
||||||
|
|
||||||
@ -151,12 +152,50 @@ function receive(data) {
|
|||||||
window.removeEventListener("keyup", keyEvent);
|
window.removeEventListener("keyup", keyEvent);
|
||||||
}
|
}
|
||||||
gSendKeyEvents = value;
|
gSendKeyEvents = value;
|
||||||
|
} else if (line && line[0] && line[0].action == "getCurrentPosition") {
|
||||||
|
navigator.geolocation.getCurrentPosition(geolocationPosition, geolocationError, line[0].options);
|
||||||
|
} else if (line && line[0] && line[0].action == "watchPosition") {
|
||||||
|
if (navigator && navigator.geolocation && gGeolocatorWatch === undefined) {
|
||||||
|
gGeolocatorWatch = navigator.geolocation.watchPosition(geolocationPosition, geolocationError, line[0].options);
|
||||||
|
}
|
||||||
|
} else if (line && line[0] && line[0].action == "clearWatch") {
|
||||||
|
if (navigator && navigator.geolocation && gGeolocatorWatch !== undefined) {
|
||||||
|
navigator.geolocation.clearWatch(gGeolocatorWatch);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
print(document.getElementById(target), line);
|
print(document.getElementById(target), line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function geolocationPosition(position) {
|
||||||
|
send({
|
||||||
|
event: 'geolocation',
|
||||||
|
position: {
|
||||||
|
timestamp: position.timestamp,
|
||||||
|
coords: {
|
||||||
|
latitude: position.coords.latitude,
|
||||||
|
longitude: position.coords.longitude,
|
||||||
|
altitude: position.coords.altitude,
|
||||||
|
accuracy: position.coords.accuracy,
|
||||||
|
altitudeAccuracy: position.coords.altitudeAccuracy,
|
||||||
|
heading: position.coords.heading,
|
||||||
|
speed: position.coords.speed,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function geolocationError(error) {
|
||||||
|
send({
|
||||||
|
event: 'geolocation',
|
||||||
|
error: {
|
||||||
|
code: error.code,
|
||||||
|
message: error.message,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function keyEvent(event) {
|
function keyEvent(event) {
|
||||||
send({
|
send({
|
||||||
event: "key",
|
event: "key",
|
||||||
@ -493,6 +532,10 @@ function connectSocket() {
|
|||||||
['setTitle', 'value'],
|
['setTitle', 'value'],
|
||||||
['split', 'options'],
|
['split', 'options'],
|
||||||
['setSendKeyEvents', 'value'],
|
['setSendKeyEvents', 'value'],
|
||||||
|
|
||||||
|
['getCurrentPosition', 'options'],
|
||||||
|
['watchPosition', 'options'],
|
||||||
|
['clearWatch'],
|
||||||
],
|
],
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
19
packages/cory/geolocation/geolocation.js
Normal file
19
packages/cory/geolocation/geolocation.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
core.register("geolocation", function(event) {
|
||||||
|
terminal.print("hi");
|
||||||
|
terminal.cork();
|
||||||
|
if (event.position) {
|
||||||
|
for (let field in event.position.coords) {
|
||||||
|
let value = event.position.coords[field];
|
||||||
|
terminal.print(field, ": ", value != null ? value.toString() : "null");
|
||||||
|
}
|
||||||
|
} else if (event.error) {
|
||||||
|
terminal.print(event.error.message);
|
||||||
|
terminal.clearWatch();
|
||||||
|
}
|
||||||
|
terminal.uncork();
|
||||||
|
});
|
||||||
|
|
||||||
|
terminal.watchPosition({enableHighAccuracy: true});
|
||||||
|
//terminal.watchPosition();
|
Loading…
Reference in New Issue
Block a user