Practical tasks to perform and ensure that the basis of the chapter has been understood.
Assignment 1 (mandatory)
Fetch and display the geolocation of the user
Create a web application that fetches the position of the user using the geolocation API.
Display the position in latitude and longitude somewhere in the page.
Pick a predetermined location, like where you live, and calculate the distance between the two locations and display it to the user when the position of the user has been determined.
Assignment 2 (optional)
Create a homing application that can tell you how far and in what direction a custom location is from where you are now. The application should have two buttons.
The first button determines the position of the user and stores it as the "home" position. Nothing else but a successful message about the location have been determined need to be shown.
The second button also determines the position of the user. If a "home" has been set with the first button, the application should display the distance and direction from the current position to the home position. The direction can be displayed in degrees from north (assuming the user will know where north is).
Use web local storage for storing the home position.
Assignment 3 (optional)
Homing application in PhoneGap with compass
Extend the previous assignment and package it as a PhoneGap application.
Use the watchPosition function in the geolocation API to get continuous information about the position.
Use the compass API in PhoneGap to also determine the direction that the user is facing.
Use both the compass direction and the direction to the home position to display in which way to move to get home in a better way than just "degrees from north". You don't have to display a graphical compass. It is enough to show "left" or "right" to tell the user in which way to face.
Note that the compass is not changable in the Android Emulator so you need a physical device to really try out your application, but for the assignment it is of course to have written code that accepts the same values from the PhoneGap API.