9 var final_position_latitude
= 0;
10 var final_position_longitude
= 0;
11 var initial_navigation_sent
= false;
13 function geoNavigate(msg
) {
15 document
.location
.hash
= '#' + iteration
+ ':' + msg
;
17 function geoSendInitialAlertIfNeeded() {
18 if (position_1
!= 0 && position_2
!= 0 && !initial_navigation_sent
) {
19 if (position_1
.coords
.latitude
!= position_2
.coords
.latitude
||
20 position_1
.coords
.longitude
!= position_2
.coords
.longitude
) {
21 last_error
= "TEST FAIL: watches received different locations. " +
22 " Watch 1 (" + watch_1_id
+ ") got " + position_1
+
23 " Watch 2 (" + watch_2_id
+ ") got " + position_2
;
25 initial_navigation_sent
= true;
26 geoNavigate("Both watches received initial position");
29 function geoSuccessCallback1(position
) {
30 position_1
= position
;
31 geoSendInitialAlertIfNeeded();
32 if (position
.coords
.latitude
== final_position_latitude
&&
33 position
.coords
.longitude
== final_position_longitude
) {
34 geoNavigate("Watch ID " + watch_1_id
+ " got final position.");
37 function geoSuccessCallback2(position
) {
38 navigator
.geolocation
.clearWatch(watch_2_id
);
39 position_2
= position
;
40 geoSendInitialAlertIfNeeded();
41 if (position
.coords
.latitude
== final_position_latitude
||
42 position
.coords
.longitude
== final_position_longitude
) {
43 last_error
= "TEST FAIL: watch 2 received the final position";
44 geoNavigate(last_error
);
47 function geoErrorCallback(error
) {
49 geoNavigate("Got error: " + error
);
52 watch_1_id
= navigator
.geolocation
.watchPosition(
53 geoSuccessCallback1
, geoErrorCallback
,
54 {maximumAge
:600000, timeout
:100000, enableHighAccuracy
:false});
56 return "Bad watch 1 ID";
57 watch_2_id
= navigator
.geolocation
.watchPosition(
58 geoSuccessCallback2
, geoErrorCallback
,
59 {maximumAge
:600000, timeout
:100000, enableHighAccuracy
:true});
61 return "Bad watch 2 ID";
62 if (watch_1_id
== watch_2_id
)
63 return "Watch 1 & 2 share ID " + watch_1_id
;
65 function geoGetLastPositionLatitude() {
66 return "" + position_1
.coords
.latitude
;
68 function geoGetLastPositionLongitude() {
69 return "" + position_1
.coords
.longitude
;
71 function geoGetLastError() {
72 return "" + (last_error
? last_error
: 0);
74 function geoSetFinalPosition(latitude
, longitude
) {
75 final_position_latitude
= latitude
;
76 final_position_longitude
= longitude
;
82 <input type=
"button" value=
"manual" onclick=
"geoStart()"/>