We test, with an if statement, for the presence of the navigator.geolocation object; if so, we call the getCurrentPosition function. We write two functions, locateSuccess and locateFail, to handle the success and failure cases, respectively.
Of course, we could extend this application extensively: we might use Google's
library to allow the user to perform a search for "bookstores" and to return human-friendly addresses (hopefully Nan & Bob's!), rather than latitude and longitude. Check out the Google Maps Demo Gallery for some inspiration and code samples.
The parameter passed to the success function, which we named loc in our example above, exposes a useful set of properties:
|coords.altitude||meters (may be null)|
|coords.altitudeAccuracy||meters (may be null)|
|coords.heading||degrees clockwise (may be null)|
|coords.speed||meters/second (may be null)|
|timestamp||a date and time|