diff --git a/bin/templates/project/phonegap/templates/project/assets/www/index.html b/bin/templates/project/phonegap/templates/project/assets/www/index.html
index a3bf1635..d89121be 100644
--- a/bin/templates/project/phonegap/templates/project/assets/www/index.html
+++ b/bin/templates/project/phonegap/templates/project/assets/www/index.html
@@ -4,7 +4,7 @@
PhoneGap
-
+
@@ -29,8 +29,12 @@
Beep
Vibrate
Get a Picture
- Get Phone's Contacts
- Check Network
+ Get Phone's Contacts
+ Check Network
+
+ - Compass Heading:
- Off
+
+ Toggle Compass
diff --git a/bin/templates/project/phonegap/templates/project/assets/www/main.js b/bin/templates/project/phonegap/templates/project/assets/www/main.js
index 1001aabc..f6316928 100644
--- a/bin/templates/project/phonegap/templates/project/assets/www/main.js
+++ b/bin/templates/project/phonegap/templates/project/assets/www/main.js
@@ -119,6 +119,25 @@ function check_network() {
confirm('Connection type:\n ' + states[networkState]);
}
+var watchID = null;
+
+function updateHeading(h) {
+ document.getElementById('h').innerHTML = h.magneticHeading;
+}
+
+function toggleCompass() {
+ if (watchID !== null) {
+ navigator.compass.clearWatch(watchID);
+ watchID = null;
+ updateHeading({ magneticHeading : "Off"});
+ } else {
+ var options = { frequency: 1000 };
+ watchID = navigator.compass.watchHeading(updateHeading, function(e) {
+ alert('Compass Error: ' + e.code);
+ }, options);
+ }
+}
+
function init() {
// the next line makes it impossible to see Contacts on the HTC Evo since it
// doesn't have a scroll button