forked from sintaxi/phonegap
/
cordova_compass_compass.md.html
747 lines (615 loc) · 29.1 KB
/
cordova_compass_compass.md.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
<!DOCTYPE html>
<!--
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.
--><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
<meta name="generator" content="joDoc">
<title>PhoneGap API Documentation</title>
<link rel="stylesheet" type="text/css" href="index.css">
<link rel="stylesheet" type="text/css" href="mobile.css" media="only screen and (max-device-width: 1024px)">
<link rel="stylesheet" type="text/css" href="prettify/prettify.css">
</head>
<body>
<div id="header">
<h1><a href="index.html">PhoneGap Documentation</a></h1>
<small>
<select><optgroup label="English" value="en">
<option value="edge">edge</option>
<option value="2.6.0rc1">2.6.0rc1</option>
<option selected value="2.6.0">2.6.0</option>
<option value="2.5.0rc1">2.5.0rc1</option>
<option value="2.5.0">2.5.0</option>
<option value="2.4.0rc1">2.4.0rc1</option>
<option value="2.4.0">2.4.0</option>
<option value="2.3.0rc2">2.3.0rc2</option>
<option value="2.3.0rc1">2.3.0rc1</option>
<option value="2.3.0">2.3.0</option>
<option value="2.2.0rc2">2.2.0rc2</option>
<option value="2.2.0rc1">2.2.0rc1</option>
<option value="2.2.0">2.2.0</option>
<option value="2.1.0rc2">2.1.0rc2</option>
<option value="2.1.0rc1">2.1.0rc1</option>
<option value="2.1.0">2.1.0</option>
<option value="2.0.0rc1">2.0.0rc1</option>
<option value="2.0.0">2.0.0</option>
<option value="1.9.0rc1">1.9.0rc1</option>
<option value="1.9.0">1.9.0</option>
<option value="1.8.1">1.8.1</option>
<option value="1.8.0rc1">1.8.0rc1</option>
<option value="1.8.0">1.8.0</option>
<option value="1.7.0rc1">1.7.0rc1</option>
<option value="1.7.0">1.7.0</option>
<option value="1.6.1">1.6.1</option>
<option value="1.6.0rc1">1.6.0rc1</option>
<option value="1.6.0">1.6.0</option>
<option value="1.5.0rc1">1.5.0rc1</option>
<option value="1.5.0">1.5.0</option>
<option value="1.4.1">1.4.1</option>
<option value="1.4.0rc1">1.4.0rc1</option>
<option value="1.4.0">1.4.0</option>
<option value="1.3.0">1.3.0</option>
<option value="1.2.0">1.2.0</option>
<option value="1.1.0">1.1.0</option>
<option value="1.0.0rc3">1.0.0rc3</option>
<option value="1.0.0rc2">1.0.0rc2</option>
<option value="1.0.0rc1">1.0.0rc1</option>
<option value="1.0.0">1.0.0</option>
<option value="0.9.6">0.9.6</option>
<option value="0.9.5.1">0.9.5.1</option>
<option value="0.9.5">0.9.5</option>
<option value="0.9.4">0.9.4</option>
<option value="0.9.3">0.9.3</option>
<option value="0.9.2">0.9.2</option>
</optgroup>
<optgroup label="Español" value="es"><option value="1.0.0">1.0.0</option></optgroup>
<optgroup label="Français" value="fr">
<option value="1.3.0">1.3.0</option>
<option value="1.2.0">1.2.0</option>
<option value="1.1.0">1.1.0</option>
</optgroup>
<optgroup label="Japanese" value="jp">
<option value="2.2.0">2.2.0</option>
<option value="2.1.0">2.1.0</option>
<option value="2.0.0">2.0.0</option>
<option value="1.9.0">1.9.0</option>
<option value="1.8.1">1.8.1</option>
<option value="1.7.0">1.7.0</option>
<option value="0.9.5">0.9.5</option>
</optgroup>
<optgroup label="Korean" value="kr"><option value="2.0.0">2.0.0</option></optgroup></select></small>
</div>
<div id="subheader">
<h1>Compass</h1>
<small><select><option value="Compass">Compass</option>
<option value="Compass_methods"> - Methods</option>
<option value="Compass_arguments"> - Arguments</option>
<option value="Compass_permissions"> - Permissions</option>
<option value="compass.getCurrentHeading">compass.getCurrentHeading</option>
<option value="compass.getCurrentHeading_description"> - Description</option>
<option value="compass.getCurrentHeading_supported_platforms"> - Supported Platforms</option>
<option value="compass.getCurrentHeading_quick_example"> - Quick Example</option>
<option value="compass.getCurrentHeading_full_example"> - Full Example</option>
<option value="compass.watchHeading">compass.watchHeading</option>
<option value="compass.watchHeading_description"> - Description</option>
<option value="compass.watchHeading_supported_platforms"> - Supported Platforms</option>
<option value="compass.watchHeading_quick_example"> - Quick Example</option>
<option value="compass.watchHeading_full_example"> - Full Example</option>
<option value="compass.watchHeading_ios_quirks"> - iOS Quirks</option>
<option value="compass.clearWatch">compass.clearWatch</option>
<option value="compass.clearWatch_supported_platforms"> - Supported Platforms</option>
<option value="compass.clearWatch_quick_example"> - Quick Example</option>
<option value="compass.clearWatch_full_example"> - Full Example</option>
<option value="compass.watchHeadingFilter">compass.watchHeadingFilter</option>
<option value="compass.clearWatchFilter">compass.clearWatchFilter</option>
<option value="compassSuccess">compassSuccess</option>
<option value="compassSuccess_parameters"> - Parameters</option>
<option value="compassSuccess_example"> - Example</option>
<option value="compassError">compassError</option>
<option value="compassError_example"> - Example</option>
<option value="compassOptions">compassOptions</option>
<option value="compassOptions_options"> - Options</option>
<option value="compassOptions_windows_phone_7_and_8_quirks"> - Windows Phone 7 and 8 Quirks</option>
<option value="compassOptions_bada_quirks"> - Bada Quirks</option>
<option value="compassOptions_tizen_quirks"> - Tizen Quirks</option>
<option value="compassHeading">compassHeading</option>
<option value="compassHeading_properties"> - Properties</option>
<option value="compassHeading_description"> - Description</option>
<option value="compassHeading_android_quirks"> - Android Quirks</option>
<option value="compassHeading_ios_quirks"> - iOS Quirks</option>
<option value="CompassError">CompassError</option>
<option value="CompassError_properties"> - Properties</option>
<option value="CompassError_constants"> - Constants</option>
<option value="CompassError_description"> - Description</option></select></small>
</div>
<div id="sidebar">
<div class="vertical_divider"></div>
<h1>API Reference</h1>
<ul>
<li><a href="cordova_accelerometer_accelerometer.md.html#Accelerometer">Accelerometer</a></li>
<li><a href="cordova_camera_camera.md.html#Camera">Camera</a></li>
<li><a href="cordova_media_capture_capture.md.html#Capture">Capture</a></li>
<li><a href="cordova_compass_compass.md.html#Compass">Compass</a></li>
<li><a href="cordova_connection_connection.md.html#Connection">Connection</a></li>
<li><a href="cordova_contacts_contacts.md.html#Contacts">Contacts</a></li>
<li><a href="cordova_device_device.md.html#Device">Device</a></li>
<li><a href="cordova_events_events.md.html#Events">Events</a></li>
<li><a href="cordova_file_file.md.html#File">File</a></li>
<li><a href="cordova_geolocation_geolocation.md.html#Geolocation">Geolocation</a></li>
<li><a href="cordova_globalization_globalization.md.html#Globalization">Globalization</a></li>
<li><a href="cordova_inappbrowser_inappbrowser.md.html#InAppBrowser">InAppBrowser</a></li>
<li><a href="cordova_media_media.md.html#Media">Media</a></li>
<li><a href="cordova_notification_notification.md.html#Notification">Notification</a></li>
<li><a href="cordova_splashscreen_splashscreen.md.html#Splashscreen">Splashscreen</a></li>
<li><a href="cordova_storage_storage.md.html#Storage">Storage</a></li>
</ul>
<h1>Guides</h1>
<ul>
<li><a href="guide_getting-started_index.md.html#Getting%20Started%20Guides">Getting Started Guides</a></li>
<li><a href="guide_command-line_index.md.html#Command-Line%20Usage">Command-Line Usage</a></li>
<li><a href="guide_upgrading_index.md.html#Upgrading%20Guides">Upgrading Guides</a></li>
<li><a href="guide_project-settings_index.md.html#Project%20Settings">Project Settings</a></li>
<li><a href="guide_plugin-development_index.md.html#Plugin%20Development%20Guide">Plugin Development Guide</a></li>
<li><a href="guide_whitelist_index.md.html#Domain%20Whitelist%20Guide">Domain Whitelist Guide</a></li>
<li><a href="guide_cordova-webview_index.md.html#Embedding%20WebView">Embedding WebView</a></li>
<li><a href="_index.html">Keyword Index</a></li>
</ul>
</div>
<div id="scrollable">
<div id="content">
<h1><a name="Compass">Compass</a></h1>
<blockquote>
<p>Obtains the direction that the device is pointing.</p>
</blockquote>
<h2>
<a name="Compass_methods">Methods</a>
</h2>
<ul>
<li><a href="cordova_compass_compass.md.html#compass.getCurrentHeading">compass.getCurrentHeading</a></li>
<li><a href="cordova_compass_compass.md.html#compass.watchHeading">compass.watchHeading</a></li>
<li><a href="cordova_compass_compass.md.html#compass.clearWatch">compass.clearWatch</a></li>
<li>
<a href="cordova_compass_compass.md.html#compass.watchHeadingFilter">compass.watchHeadingFilter</a> (obsolete)</li>
<li>
<a href="cordova_compass_compass.md.html#compass.clearWatchFilter">compass.clearWatchFilter</a> (obsolete)</li>
</ul>
<h2>
<a name="Compass_arguments">Arguments</a>
</h2>
<ul>
<li><a href="cordova_compass_compass.md.html#compassSuccess">compassSuccess</a></li>
<li><a href="cordova_compass_compass.md.html#compassError">compassError</a></li>
<li><a href="cordova_compass_compass.md.html#compassOptions">compassOptions</a></li>
<li><a href="cordova_compass_compass.md.html#compassHeading">compassHeading</a></li>
</ul>
<h2>
<a name="Compass_permissions">Permissions</a>
</h2>
<h3>Android</h3>
<h4>app/res/xml/config.xml</h4>
<pre class="prettyprint"><code><plugin name="<a href="cordova_compass_compass.md.html#Compass">Compass</a>" value="org.apache.cordova.CompassListener" />
</code></pre>
<h3>Bada</h3>
<pre class="prettyprint"><code>No permissions are required.
</code></pre>
<h3>BlackBerry WebWorks</h3>
<pre class="prettyprint"><code>No permissions are required.
</code></pre>
<h3>iOS</h3>
<h4>config.xml</h4>
<pre class="prettyprint"><code><plugin name="<a href="cordova_compass_compass.md.html#Compass">Compass</a>" value="CDVLocation" />
</code></pre>
<h3>webOS</h3>
<pre class="prettyprint"><code>No permissions are required.
</code></pre>
<h3>Windows Phone</h3>
<h4>Properties/WPAppManifest.xml</h4>
<pre class="prettyprint"><code><Capabilities>
<Capability Name="ID_CAP_SENSORS" />
</Capabilities>
</code></pre>
<p>Reference: <a class="external" href="http://msdn.microsoft.com/en-us/library/ff769509%28v=vs.92%29.aspx">Application Manifest for Windows Phone</a></p>
<h3>Tizen</h3>
<pre class="prettyprint"><code>No permissions are required.
</code></pre>
<hr>
<h1><a name="compass.getCurrentHeading">compass.getCurrentHeading</a></h1>
<p>Get the current compass heading.</p>
<pre class="prettyprint"><code>navigator.<a href="cordova_compass_compass.md.html#compass.getCurrentHeading">compass.getCurrentHeading</a>(<a href="cordova_compass_compass.md.html#compassSuccess">compassSuccess</a>, <a href="cordova_compass_compass.md.html#compassError">compassError</a>, <a href="cordova_compass_compass.md.html#compassOptions">compassOptions</a>);
</code></pre>
<h2>
<a name="compass.getCurrentHeading_description">Description</a>
</h2>
<p>The compass is a sensor that detects the direction or heading that the device is pointed. It measures the heading in degrees from 0 to 359.99.</p>
<p>The compass heading information is returned via a CompassHeading object using the <code><a href="cordova_compass_compass.md.html#compassSuccess">compassSuccess</a></code> callback function.</p>
<h2>
<a name="compass.getCurrentHeading_supported_platforms">Supported Platforms</a>
</h2>
<ul>
<li>Android</li>
<li>iPhone</li>
<li>Windows Phone 7 and 8 ( if available in hardware )</li>
<li>Bada 1.2 & 2.x</li>
<li>webOS</li>
<li>Tizen</li>
<li>Windows 8</li>
</ul>
<h2>
<a name="compass.getCurrentHeading_quick_example">Quick Example</a>
</h2>
<pre class="prettyprint"><code>function onSuccess(heading) {
alert('Heading: ' + heading.magneticHeading);
};
function onError(error) {
alert('<a href="cordova_compass_compass.md.html#CompassError">CompassError</a>: ' + error.code);
};
navigator.<a href="cordova_compass_compass.md.html#compass.getCurrentHeading">compass.getCurrentHeading</a>(onSuccess, onError);
</code></pre>
<h2>
<a name="compass.getCurrentHeading_full_example">Full Example</a>
</h2>
<pre class="prettyprint"><code><!DOCTYPE html>
<html>
<head>
<title><a href="cordova_compass_compass.md.html#Compass">Compass</a> Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.6.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.<a href="cordova_inappbrowser_inappbrowser.md.html#addEventListener">addEventListener</a>("<a href="cordova_events_events.md.html#deviceready">deviceready</a>", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
navigator.<a href="cordova_compass_compass.md.html#compass.getCurrentHeading">compass.getCurrentHeading</a>(onSuccess, onError);
}
// onSuccess: Get the current heading
//
function onSuccess(heading) {
alert('Heading: ' + heading.magneticHeading);
}
// onError: Failed to get the heading
//
function onError(<a href="cordova_compass_compass.md.html#compassError">compassError</a>) {
alert('<a href="cordova_compass_compass.md.html#Compass">Compass</a> Error: ' + <a href="cordova_compass_compass.md.html#compassError">compassError</a>.code);
}
</script>
</head>
<body>
<h1>Example</h1>
<p>getCurrentHeading</p>
</body>
</html>
</code></pre>
<hr>
<h1><a name="compass.watchHeading">compass.watchHeading</a></h1>
<p>At a regular interval, get the compass heading in degrees.</p>
<pre class="prettyprint"><code>var watchID = navigator.<a href="cordova_compass_compass.md.html#compass.watchHeading">compass.watchHeading</a>(<a href="cordova_compass_compass.md.html#compassSuccess">compassSuccess</a>, <a href="cordova_compass_compass.md.html#compassError">compassError</a>, [<a href="cordova_compass_compass.md.html#compassOptions">compassOptions</a>]);
</code></pre>
<h2>
<a name="compass.watchHeading_description">Description</a>
</h2>
<p>The compass is a sensor that detects the direction or heading that the device is pointed. It measures the heading in degrees from 0 to 359.99.</p>
<p>The <code><a href="cordova_compass_compass.md.html#compass.watchHeading">compass.watchHeading</a></code> gets the device's current heading at a regular interval. Each time the heading is retrieved, the <code>headingSuccess</code> callback function is executed. Specify the interval in milliseconds via the <code>frequency</code> parameter in the <code><a href="cordova_compass_compass.md.html#compassOptions">compassOptions</a></code> object.</p>
<p>The returned watch ID references references the compass watch interval. The watch ID can be used with <code><a href="cordova_compass_compass.md.html#compass.clearWatch">compass.clearWatch</a></code> to stop watching the compass.</p>
<h2>
<a name="compass.watchHeading_supported_platforms">Supported Platforms</a>
</h2>
<ul>
<li>Android</li>
<li>iPhone</li>
<li>Windows Phone 7 and 8 ( if available in hardware )</li>
<li>Bada 1.2 & 2.x</li>
<li>webOS</li>
<li>Tizen</li>
<li>Windows 8</li>
</ul>
<h2>
<a name="compass.watchHeading_quick_example">Quick Example</a>
</h2>
<pre class="prettyprint"><code>function onSuccess(heading) {
var element = document.getElementById('heading');
element.innerHTML = 'Heading: ' + heading.magneticHeading;
};
function onError(<a href="cordova_compass_compass.md.html#compassError">compassError</a>) {
alert('<a href="cordova_compass_compass.md.html#Compass">Compass</a> error: ' + <a href="cordova_compass_compass.md.html#compassError">compassError</a>.code);
};
var options = { frequency: 3000 }; // Update every 3 seconds
var watchID = navigator.<a href="cordova_compass_compass.md.html#compass.watchHeading">compass.watchHeading</a>(onSuccess, onError, options);
</code></pre>
<h2>
<a name="compass.watchHeading_full_example">Full Example</a>
</h2>
<pre class="prettyprint"><code><!DOCTYPE html>
<html>
<head>
<title><a href="cordova_compass_compass.md.html#Compass">Compass</a> Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.6.0.js"></script>
<script type="text/javascript" charset="utf-8">
// The watch id references the current `watchHeading`
var watchID = null;
// Wait for Cordova to load
//
document.<a href="cordova_inappbrowser_inappbrowser.md.html#addEventListener">addEventListener</a>("<a href="cordova_events_events.md.html#deviceready">deviceready</a>", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
startWatch();
}
// Start watching the compass
//
function startWatch() {
// Update compass every 3 seconds
var options = { frequency: 3000 };
watchID = navigator.<a href="cordova_compass_compass.md.html#compass.watchHeading">compass.watchHeading</a>(onSuccess, onError, options);
}
// Stop watching the compass
//
function stopWatch() {
if (watchID) {
navigator.<a href="cordova_compass_compass.md.html#compass.clearWatch">compass.clearWatch</a>(watchID);
watchID = null;
}
}
// onSuccess: Get the current heading
//
function onSuccess(heading) {
var element = document.getElementById('heading');
element.innerHTML = 'Heading: ' + heading.magneticHeading;
}
// onError: Failed to get the heading
//
function onError(<a href="cordova_compass_compass.md.html#compassError">compassError</a>) {
alert('<a href="cordova_compass_compass.md.html#Compass">Compass</a> error: ' + <a href="cordova_compass_compass.md.html#compassError">compassError</a>.code);
}
</script>
</head>
<body>
<div id="heading">Waiting for heading...</div>
<button onclick="startWatch();">Start Watching</button>
<button onclick="stopWatch();">Stop Watching</button>
</body>
</html>
</code></pre>
<h2>
<a name="compass.watchHeading_ios_quirks">iOS Quirks</a>
</h2>
<p>In iOS <code><a href="cordova_compass_compass.md.html#compass.watchHeading">compass.watchHeading</a></code> can also get the device's current heading when it changes by a specified number of degrees. Each time the heading changes by the specified number of degrees or more, the <code>headingSuccess</code> callback function is called. Specify the degrees of change via the <code>filter</code> parameter in the <code><a href="cordova_compass_compass.md.html#compassOptions">compassOptions</a></code> object. Clear the watch as normal by passing the returned watch ID to <code><a href="cordova_compass_compass.md.html#compass.clearWatch">compass.clearWatch</a></code>. This functionality replaces the previously separate, iOS only functions, watchHeadingFilter and clearWatchFilter, which were removed in 1.6.</p>
<p>In iOS only one watchHeading can be in effect at one time. If a watchHeading via filter is in effect, calling getCurrentHeading or watchHeading will use the existing filter value for specifying heading changes. On iOS watching heading changes via a filter is more efficient than via time.</p>
<hr>
<h1><a name="compass.clearWatch">compass.clearWatch</a></h1>
<p>Stop watching the compass referenced by the watch ID parameter.</p>
<pre class="prettyprint"><code>navigator.<a href="cordova_compass_compass.md.html#compass.clearWatch">compass.clearWatch</a>(watchID);
</code></pre>
<ul>
<li>
<strong>watchID</strong>: The ID returned by <code><a href="cordova_compass_compass.md.html#compass.watchHeading">compass.watchHeading</a></code>.</li>
</ul>
<h2>
<a name="compass.clearWatch_supported_platforms">Supported Platforms</a>
</h2>
<ul>
<li>Android</li>
<li>iPhone</li>
<li>Windows Phone 7 and 8 ( if available in hardware )</li>
<li>Bada 1.2 & 2.x</li>
<li>webOS</li>
<li>Tizen</li>
<li>Windows 8</li>
</ul>
<h2>
<a name="compass.clearWatch_quick_example">Quick Example</a>
</h2>
<pre class="prettyprint"><code>var watchID = navigator.<a href="cordova_compass_compass.md.html#compass.watchHeading">compass.watchHeading</a>(onSuccess, onError, options);
// ... later on ...
navigator.<a href="cordova_compass_compass.md.html#compass.clearWatch">compass.clearWatch</a>(watchID);
</code></pre>
<h2>
<a name="compass.clearWatch_full_example">Full Example</a>
</h2>
<pre class="prettyprint"><code><!DOCTYPE html>
<html>
<head>
<title><a href="cordova_compass_compass.md.html#Compass">Compass</a> Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.6.0.js"></script>
<script type="text/javascript" charset="utf-8">
// The watch id references the current `watchHeading`
var watchID = null;
// Wait for Cordova to load
//
document.<a href="cordova_inappbrowser_inappbrowser.md.html#addEventListener">addEventListener</a>("<a href="cordova_events_events.md.html#deviceready">deviceready</a>", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
startWatch();
}
// Start watching the compass
//
function startWatch() {
// Update compass every 3 seconds
var options = { frequency: 3000 };
watchID = navigator.<a href="cordova_compass_compass.md.html#compass.watchHeading">compass.watchHeading</a>(onSuccess, onError, options);
}
// Stop watching the compass
//
function stopWatch() {
if (watchID) {
navigator.<a href="cordova_compass_compass.md.html#compass.clearWatch">compass.clearWatch</a>(watchID);
watchID = null;
}
}
// onSuccess: Get the current heading
//
function onSuccess(heading) {
var element = document.getElementById('heading');
element.innerHTML = 'Heading: ' + heading.magneticHeading;
}
// onError: Failed to get the heading
//
function onError(<a href="cordova_compass_compass.md.html#compassError">compassError</a>) {
alert('<a href="cordova_compass_compass.md.html#Compass">Compass</a> error: ' + <a href="cordova_compass_compass.md.html#compassError">compassError</a>.code);
}
</script>
</head>
<body>
<div id="heading">Waiting for heading...</div>
<button onclick="startWatch();">Start Watching</button>
<button onclick="stopWatch();">Stop Watching</button>
</body>
</html>
</code></pre>
<hr>
<h1><a name="compass.watchHeadingFilter">compass.watchHeadingFilter</a></h1>
<p>No longer supported as of 1.6, see <code><a href="cordova_compass_compass.md.html#compass.watchHeading">compass.watchHeading</a></code> for equivalent functionality.</p>
<hr>
<h1><a name="compass.clearWatchFilter">compass.clearWatchFilter</a></h1>
<p>No longer supported as of 1.6. See <code><a href="cordova_compass_compass.md.html#compass.clearWatch">compass.clearWatch</a></code>.</p>
<hr>
<h1><a name="compassSuccess">compassSuccess</a></h1>
<p>onSuccess callback function that provides the compass heading information via a <a href="cordova_compass_compass.md.html#compassHeading">compassHeading</a> object.</p>
<pre class="prettyprint"><code>function(heading) {
// Do something
}
</code></pre>
<h2>
<a name="compassSuccess_parameters">Parameters</a>
</h2>
<ul>
<li>
<strong>heading:</strong> The heading information. <em>(<a href="cordova_compass_compass.md.html#compassHeading">compassHeading</a>)</em>
</li>
</ul>
<h2>
<a name="compassSuccess_example">Example</a>
</h2>
<pre class="prettyprint"><code>function onSuccess(heading) {
alert('Heading: ' + heading.magneticHeading);
};
</code></pre>
<hr>
<h1><a name="compassError">compassError</a></h1>
<p>onError callback function for compass functions. </p>
<h2>
<a name="compassError_example">Example</a>
</h2>
<pre class="prettyprint"><code>function(<a href="cordova_compass_compass.md.html#CompassError">CompassError</a>) {
// Handle the error
}
</code></pre>
<hr>
<h1><a name="compassOptions">compassOptions</a></h1>
<p>An optional parameter to customize the retrieval of the compass.</p>
<h2>
<a name="compassOptions_options">Options</a>
</h2>
<ul>
<li>
<strong>frequency:</strong> How often to retrieve the compass heading in milliseconds. <em>(Number)</em> (Default: 100)</li>
<li>
<strong>filter:</strong> The change in degrees required to initiate a watchHeading success callback. <em>(Number)</em>
</li>
</ul>
<p>Android Quirks</p>
<hr>
<ul>
<li>filter is not supported.</li>
</ul>
<h2>
<a name="compassOptions_windows_phone_7_and_8_quirks">Windows Phone 7 and 8 Quirks</a>
</h2>
<ul>
<li>filter is not supported.</li>
</ul>
<h2>
<a name="compassOptions_bada_quirks">Bada Quirks</a>
</h2>
<ul>
<li>filter is not supported.</li>
</ul>
<h2>
<a name="compassOptions_tizen_quirks">Tizen Quirks</a>
</h2>
<ul>
<li>filter is not supported.</li>
</ul>
<hr>
<h1><a name="compassHeading">compassHeading</a></h1>
<p>A <code>CompassHeading</code> object is returned to the <code><a href="cordova_compass_compass.md.html#compassSuccess">compassSuccess</a></code> callback function when an error occurs.</p>
<h2>
<a name="compassHeading_properties">Properties</a>
</h2>
<ul>
<li>
<strong>magneticHeading:</strong> The heading in degrees from 0 - 359.99 at a single moment in time. <em>(Number)</em>
</li>
<li>
<strong>trueHeading:</strong> The heading relative to the geographic North Pole in degrees 0 - 359.99 at a single moment in time. A negative value indicates that the true heading could not be determined. <em>(Number)</em>
</li>
<li>
<strong>headingAccuracy:</strong> The deviation in degrees between the reported heading and the true heading. <em>(Number)</em>
</li>
<li>
<strong>timestamp:</strong> The time at which this heading was determined. <em>(milliseconds)</em>
</li>
</ul>
<h2>
<a name="compassHeading_description">Description</a>
</h2>
<p>The <code>CompassHeading</code> object is returned to the user through the <code><a href="cordova_compass_compass.md.html#compassSuccess">compassSuccess</a></code> callback function.</p>
<h2>
<a name="compassHeading_android_quirks">Android Quirks</a>
</h2>
<ul>
<li>trueHeading is not supported. It will report the same value as magneticHeading</li>
<li>headingAccuracy will always be 0 as there is no difference between the magneticHeading and trueHeading on Android.</li>
</ul>
<h2>
<a name="compassHeading_ios_quirks">iOS Quirks</a>
</h2>
<ul>
<li>trueHeading is only returned when location services are running via <code>navigator.geolocation.watchLocation()</code>
</li>
<li>For iOS > 4 devices, if the device is rotated and the app supports that orientation, the heading values will be reported
back with respect to the current orientation.</li>
</ul>
<hr>
<h1><a name="CompassError">CompassError</a></h1>
<p>A <code><a href="cordova_compass_compass.md.html#CompassError">CompassError</a></code> object is returned to the <code><a href="cordova_compass_compass.md.html#compassError">compassError</a></code> callback function when an error occurs.</p>
<h2>
<a name="CompassError_properties">Properties</a>
</h2>
<ul>
<li>
<strong>code:</strong> One of the predefined error codes listed below.</li>
</ul>
<h2>
<a name="CompassError_constants">Constants</a>
</h2>
<ul>
<li>
<code><a href="cordova_compass_compass.md.html#CompassError">CompassError</a>.COMPASS_INTERNAL_ERR</code> </li>
<li><code><a href="cordova_compass_compass.md.html#CompassError">CompassError</a>.COMPASS_NOT_SUPPORTED</code></li>
</ul>
<h2>
<a name="CompassError_description">Description</a>
</h2>
<p>The <code><a href="cordova_compass_compass.md.html#CompassError">CompassError</a></code> object is returned to the user through the <code><a href="cordova_compass_compass.md.html#compassError">compassError</a></code> callback function when an error occurs.</p>
</div>
</div>
<!-- Functionality and Syntax Highlighting -->
<script type="text/javascript" src="index.js"></script><script type="text/javascript" src="prettify/prettify.js"></script>
</body>
</html>