HTML and CSS Reference
In-Depth Information
The code property will be only one of the following:
PERMISSION_DENIED (numeric value 1)
POSITION_UNAVAILABLE (numeric value 2)
TIMEOUT (numeric value 3)
The message property is useful for developing and debugging but
wouldn't be appropriate to show the user. The message property
isn't always available (as it's not currently in Firefox 3.6+).
For example, if you used the following code and elected to not
share the position, the page announces “Permission denied:
means we can't determine your position.”
if (navigator.geolocation) {
¬ (position) {
var coords = position.coords;
showMap(coords.latitude, coords.longitude,
¬ coords.accuracy);
}, function (error) {
var errorTypes = {
1: 'Permission denied',
2: 'Position is not available',
3: 'Request timeout'
alert(errorTypes[error.code] + “: means we can't
¬ determine your position”);
the alternative error: on success
One alternative to the error handler is if the accuracy on the success call is a huge number. When I
once visited a page that was supposed to detect my location, whilst working from home in Brighton on
the south coast of England, the map placed me dead in the centre of London. When I checked under the
hood using Firebug's console log I could see the accuracy of the geolocation request was set to 140,000
meters—that's about 90 miles of inaccuracy; as a radius that's pretty damn inaccurate! Understandable
how the site wasn't sure exactly where I was. I would strongly recommend that while developing applica-
tions that use geolocation you also check the accuracy of the success call. If the accuracy is such a large
value, it might be worth ignoring the data altogether and letting the users tell you their location manually.
Search WWH ::

Custom Search