HTML and CSS Reference
In-Depth Information
information from your user:
1. getCurrentPosition is a one-shot method for grabbing the
user's current location.
2. watchPosition keeps an eye on the user's position and
keeps polling at regular intervals to see if that location has
changed. watchPosition mirrors getCurrentPosition 's func-
tionality, but if the user's position changes, it will also tell
your code. Note that even though watchPosition is polling
your position, it will only call your callback if the position has
changed. To stop watching, or polling, you pass the return
value from watchPosition to clearWatch which we'll see
later on.
Both getCurrentPosition and watchPosition work asynchro-
nously to ascertain the user's location. However, if this is the first
time your site has asked the user for their location, the browser
will show some kind of dialog (as we'll see in a moment) asking
for permission to share their location. If the visitor doesn't agree
to share their location, the geolocation API will call the error
handler if you've provided it with one.
The specification says:
“User agents must not send location information to
websites without the express permission of the user.”
So it's up to the browser to prompt users to inform them that
we're trying to grab their current position. Different browsers
handle this in different ways. Firefox, for example, offers a non-
modal, non-blocking alert ( Figure 9.2 ). This means your applica-
tion continues to execute. In fact, currently all desktop browsers
ask for permission the same way, in that it doesn't prompt the
user with a blocking message.
FIguRE 9.2 Firefox being
asked to share the user's
location.
 
Search WWH ::




Custom Search