Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
In this recipe, the page will use the getCurrentPosition method with a success callback function to determine your current location and display the properties of the position object returned. Use these steps and the code in Listing 10.1 to create this recipe:
1. | Create a blank HTML page with a div (called btnFindMe) and the Find Me button, which will call the findMe function when clicked. |
2. | Add the findMe function in a set of script tags with the following code to check for the Geolocation API, and then call the getCurrentPosition method: if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(geoSuccess);
} else {
document.getElementById('myLocation').innerHTML =
"Geolocation API Not Supported";
} |
3. | |
4. | Add a second div (called myLocation) to the HTML in which you will display the returned position information from the getCurrentPosition. |