/* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ /** * This class provides access to device Compass data. * @constructor */ function Compass() { /** * The last known Compass position. */ this.uuid = null; }; /** * Asynchronously aquires the current heading. * @param {Function} successCallback The function to call when the heading * data is available * @param {Function} errorCallback The function to call when there is an error * getting the heading data. * @param {PositionOptions} options The options for getting the heading data * such as timeout. */ Compass.prototype.getCurrentHeading = function(successCallback, errorCallback, options) { Cordova.exec(successCallback, errorCallback, "org.apache.cordova.Compass", "getCurrentHeading", options); }; /** * Asynchronously aquires the heading repeatedly at a given interval. * @param {Function} successCallback The function to call each time the heading * data is available * @param {Function} errorCallback The function to call when there is an error * getting the heading data. * @param {HeadingOptions} options The options for getting the heading data * such as timeout and the frequency of the watch. */ Compass.prototype.watchHeading= function(successCallback, errorCallback, options) { this.uuid = Cordova.createUUID(); Cordova.exec(successCallback, errorCallback, "org.apache.cordova.Compass", "watchHeading", [this.uuid, options.frequency || 3000]); return this.uuid; }; /** * Clears the specified heading watch. * @param {String} watchId The ID of the watch returned from #watchHeading. */ Compass.prototype.clearWatch = function(watchId) { if(this.uuid == watchId) { Cordova.exec(null, null, "org.apache.cordova.Compass", "clearWatch", [this.uuid]); this.uuid = null; } else { debugPrint('no clear watch'); } }; Cordova.addConstructor(function() { if (typeof navigator.compass == "undefined") navigator.compass = new Compass(); });