Creating a visual compass to show the device direction
The geolocation and accelerometer plugins' API provides developers with the ability to receive coordinate and heading information from the device. We can use this information to build a custom compass tool that responds to the device movement.
How to do it…
First, create a new PhoneGap project named
compass
by running the following command:phonegap create compass com.myapp.compass compass
Add the device platform. You can choose to use Android, iOS, or both:
cordova platform add ios cordova platform add android
Add the
device-orientation
,device-motion
, andgeolocation
plugins by running the following command:phonegap plugin add org.apache.cordova.device-motion phonegap plugin add org.apache.cordova.geolocation phonegap plugin add org.apache.cordova.device-orientation
Open
www/index.html
and clean up unnecessary elements; so you have the following:<!DOCTYPE html> <html> <head> <meta charset="utf-8" />...