HTML and CSS Reference
In-Depth Information
As I mentioned before, getCurrentPosition and watchPosition
mirror each other and take the same arguments:
success handler
error handler
geolocation options
A simple use of the geolocation API would be to just pass a
success handler to the getCurrentPosition method:
navigator.geolocation.getCurrentPosition(function
¬ (position) {
alert('We found you!');
// now do something with the position data
});
Got you: the success handler
If the user permits the browser to share his geolocation and
there's no other error, the success handler is called, which is the
first argument to getCurrentPosition and watchPosition .
The handler receives a Position object containing two properties:
a coords object (containing coordinate information) and a timestamp .
The coordinates object is where the interesting stuff is sitting.
There are really two grades of data in the position object. The
first grade appears in all the browsers with geolocation support:
readonly attribute double latitude
readonly attribute double longitude
readonly attribute double accuracy
Note that accuracy is the measurement of the coordinates' accu-
racy in meters. You could use this to show a radius of
accuracy if you were mapping the user's position.
Although it's difficult to confirm manually, it's likely this data
is being provided by the browser vendor's own service. For
instance, Google has a big database of location data which—
when combined with information about your request, the hard-
ware, your IP, and a bit of black magic—finds your position. This
data simply represents a snapshot of the user's position, and
doesn't contain any information that could help you work out their
speed, or direction of travel. We'll look at the voodoo magic used
to ascertain the visitor's location at the end of this chapter.
 
Search WWH ::




Custom Search