CB-9179 (ios) Fixed trueHeading being always 0
diff --git a/src/ios/CDVCompass.m b/src/ios/CDVCompass.m
index 86c4ed7..192264b 100644
--- a/src/ios/CDVCompass.m
+++ b/src/ios/CDVCompass.m
@@ -243,6 +243,7 @@
[self stopHeading:nil];
}
hData.headingStatus = HEADINGRUNNING; // to clear any error
+ __locationStarted = YES;
}
- (void)locationManager:(CLLocationManager*)manager didFailWithError:(NSError*)error
diff --git a/tests/tests.js b/tests/tests.js
index 6fd5bf3..7d56214 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -134,6 +134,66 @@
expect(typeof h.timestamp == 'number').toBe(true);
});
});
+
+ describe("Compass watch heading", function() {
+ it("compass.spec.10 watchCurrentHeading called with a Heading object", function (done) {
+ if (!isCompassAvailable) {
+ pending();
+ }
+
+ var calledOnce = false;
+
+ var watchId = navigator.compass.watchHeading(
+ function (a){
+ expect(a instanceof CompassHeading).toBe(true);
+ expect(a.magneticHeading).toBeDefined();
+ expect(typeof a.magneticHeading == 'number').toBe(true);
+ expect(a.trueHeading).not.toBe(undefined);
+ expect(typeof a.trueHeading == 'number' || a.trueHeading === null).toBe(true);
+ expect(a.headingAccuracy).not.toBe(undefined);
+ expect(typeof a.headingAccuracy == 'number' || a.headingAccuracy === null).toBe(true);
+ expect(typeof a.timestamp == 'number').toBe(true);
+
+ if (calledOnce) {
+ navigator.compass.clearWatch(watchId);
+ done();
+ }
+
+ calledOnce = true;
+ },
+ function (compassError){},
+ { frequency: 50 }
+ );
+ });
+
+ it("compass.spec.11 the watch success callback should not be called once the watch is cleared", function (done) {
+ if (!isCompassAvailable) {
+ pending();
+ }
+
+ var calledOnce = false;
+ var watchCleared = false;
+
+ var watchId = navigator.compass.watchHeading(
+ function (a){
+ // Don't invoke this function if we have cleared the watch
+ expect(watchCleared).toBe(false);
+
+ if (calledOnce) {
+ navigator.compass.clearWatch(watchId);
+ watchCleared = true;
+ setInterval(function(){
+ done();
+ }, 100);
+ }
+
+ calledOnce = true;
+ },
+ function (compassError){},
+ { frequency: 50 }
+ );
+ });
+ });
});
};
@@ -157,6 +217,19 @@
document.getElementById('compass_status').innerHTML = status;
}
+ // Success callback for both watchHeading and getCurrentHeading
+ function success(a) {
+ var magneticHeading = document.getElementById('magneticHeading');
+ var trueHeading = document.getElementById("trueHeading");
+ var headingAccuracy = document.getElementById("headingAccuracy");
+ var timestamp = document.getElementById("timestamp");
+
+ magneticHeading.innerHTML = roundNumber(a.magneticHeading);
+ trueHeading.innerHTML = roundNumber(a.trueHeading);
+ headingAccuracy.innerHTML = a.headingAccuracy;
+ timestamp.innerHTML = a.timestamp;
+ }
+
/**
* Stop watching the acceleration
*/
@@ -174,14 +247,9 @@
var watchCompass = function () {
console.log("watchCompass()");
- // Success callback
- var success = function (a) {
- document.getElementById('compassHeading').innerHTML = roundNumber(a.magneticHeading);
- };
-
// Fail callback
var fail = function (e) {
- console.log("watchCompass fail callback with error code " + e);
+ console.log("watchCompass fail callback with error: " + JSON.stringify(e));
stopCompass();
setCompassStatus(e);
};
@@ -206,14 +274,9 @@
// Stop compass if running
stopCompass();
- // Success callback
- var success = function (a) {
- document.getElementById('compassHeading').innerHTML = roundNumber(a.magneticHeading);
- };
-
// Fail callback
var fail = function (e) {
- console.log("getCompass fail callback with error code " + e.toString);
+ console.log("getCompass fail callback with error: " + JSON.stringify(e));
setCompassStatus(e);
};
@@ -234,9 +297,12 @@
contentEl.innerHTML = '<div id="info"><b>Status: </b>' +
'<span id="compass_status">Stopped</span>' +
- '<table width="100%"><tr>' +
- '<td width="33%">Heading: <span id="compassHeading"></span>' +
- '</td></tr></table></div>' +
+ '<table width="100%">' +
+ '<tr><td width="33%">Magnetic heading: <span id="magneticHeading"></span></td></tr>' +
+ '<tr><td width="33%">True heading: <span id="trueHeading"></span></td></tr>' +
+ '<tr><td width="33%">Heading accuracy: <span id="headingAccuracy"></span></td></tr>' +
+ '<tr><td width="33%">Timestamp: <span id="timestamp"></span></td></tr>' +
+ '</table></div>' +
orientation_tests;
createActionButton('Get Compass', function () {