check iOS compass calibration via webkitCompassAccuracy

Ensure that webkitCompassAccuracy is not -1 as this indicates that the
compass has not been calibrated and its values cannot be trusted.
This commit is contained in:
Paul Spencer
2013-09-09 08:05:37 -04:00
parent f56e01104b
commit 4117a5df2d

View File

@@ -122,7 +122,9 @@ ol.DeviceOrientation.prototype.orientationChange_ = function(browserEvent) {
// event.absolute is undefined in iOS.
if (goog.isBoolean(event.absolute) && event.absolute) {
this.set(ol.DeviceOrientationProperty.HEADING, alpha);
} else if (goog.isDefAndNotNull(event.webkitCompassHeading)) {
} else if (goog.isDefAndNotNull(event.webkitCompassHeading) &&
goog.isDefAndNotNull(event.webkitCompassAccuracy) &&
event.webkitCompassAccuracy != -1) {
var heading = goog.math.toRadians(event.webkitCompassHeading);
this.set(ol.DeviceOrientationProperty.HEADING, heading);
}