Fix for Issue #228: Align Compass support with iOS

This commit is contained in:
macdonst
2011-09-28 17:35:50 -04:00
parent 336a58ca5a
commit 821eb24a54
2 changed files with 228 additions and 181 deletions
+23
View File
@@ -9,6 +9,21 @@
if (!PhoneGap.hasResource("compass")) {
PhoneGap.addResource("compass");
CompassError = function(){
this.code = null;
};
// Capture error codes
CompassError.COMPASS_INTERNAL_ERR = 0;
CompassError.COMPASS_NOT_SUPPORTED = 20;
CompassHeading = function() {
this.magneticHeading = null;
this.trueHeading = null;
this.headingAccuracy = null;
this.timestamp = null;
};
/**
* This class provides access to device Compass data.
* @constructor
@@ -111,6 +126,14 @@ Compass.prototype.clearWatch = function(id) {
}
};
Compass.prototype._castDate = function(pluginResult) {
if (pluginResult.message.timestamp) {
var timestamp = new Date(pluginResult.message.timestamp);
pluginResult.message.timestamp = timestamp;
}
return pluginResult;
};
PhoneGap.addConstructor(function() {
if (typeof navigator.compass === "undefined") {
navigator.compass = new Compass();