HTML and CSS Reference
In-Depth Information
1. getCurrentPosition is a one-shot method for grabbing the
user's current location.
2. watchPosition keeps an eye on their position and keeps poll-
ing at regular intervals to see if their location has changed.
watchPosition mirrors getCurrentPosition 's functionality, but
also if the user's position changes, it will tell your code.
Both getCurrentPosition and watchPosition work asynchro-
nously to ascertain the user's location. There is one exception
to that rule: if the user is visiting your site for the fi rst time and
the browser forces a model dialog asking for permission to
share your location. When using either of these methods, most
devices will prompt the user and ask whether they want to
share their location with the application. If they don't agree to
sharing their location, and you've told the geolocation API to
pass errors to a specifi c function, it will be called with the error
The specifi cation says:
“User agents must not send location information to web-
sites 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 asking users if they want to share
their location (see Figure 9.2 ). This means your application
continues to execute.
FIGURE 9.2 Firefox being asked
to share the user's location.
Other browsers, such as Mobile Safari, prompt the user with
a model dialog, stopping all code execution until the user
responds ( Figure 9.3 ).
Search WWH ::

Custom Search