HTML and CSS Reference
In-Depth Information
number to the clearWatch() method to stop watching the user's location. The code in Listing 12-12 shows
how you can use watchPosition() and clearWatch() .
Listing 12-12. Using the watchPosition() and clearWatch() Methods
var watchId;
function StartWatch() {
watchId = window.navigator.geolocation.watchPosition(OnSuccess, OnError);
function StopWatch() {
This code defines a global variable named watchId to store the watch handle returned by
watchPosition() . The StartWatch() function calls geolocation object's watchPosition() method and
passes OnSuccess and OnError callback functions as before. The returned numeric handle is stored in the
watchId variable. StopWatch() calls the geolocation object's clearWatch() method and passes watchId as a
parameter to clear that watch.
The Geolocation API allows you to find the user's geographic location in terms of latitude and longitude.
The geolocation object property of the navigator object exposes the methods responsible for retrieving
the user's location. The getCurrentPosition() method returns the user's current location. The
watchPosition() method keeps monitoring that location until the clearWatch() method is called.
Using the Geolocation API, you can build location-aware web applications that present data based on
the user's location. You can also integrate the Geolocation API with mapping services such as Google Maps
and Bing Maps.
You've learned about all of HTML5's prominent programmable features. Although, as a web developer,
your core focus is on programmable features, at times you also need to style your web applications using
Cascading Style Sheets (CSS). CSS3 offers the latest in this area. The next chapter covers some new and
improved features.
Search WWH ::

Custom Search