Information Technology Reference
In-Depth Information
case error.PERMISSION_DENIED:
alert ('Geolocation returned permission denied (did you deny
access?)');
break;
case error.UNKNOWN_ERROR:
alert ('Geolocation encountered an unknown error');
break;
}
}
);
<! -- alert("Confirm geolocation access before clicking OK"); -->
} else {
geoData = "Your browser does not support HTML5 geolocation";
}
changeDiv ("myCheckIn",geoData);
}
In the bolded text, you'll see we've changed the method signature (overloaded version)
of the getCurrentPosition() function to register our error callback, and alert the user
should any error condition be returned. We're in the fortunate position (OK, we're being
sarcastic here) that the Android emulator is notoriously slow and temperamental when it
comes to responding to geolocation requests. For this reason, it's always good practice
to test your code on real devices, as well as the emulator. The authors managed to
trigger a POSITION_UNAVAILABLE error without really trying, on our first attempt. You can
see the results in Figure 9-6.
Figure 9-6. A geolocation attempt returns a POSITION_UNAVAILABLE error
As we did with our supportsGeo() function, you should turn this style of error checking
into a utility function for use throughout your code, rather than bombard the user with
alert-style errors—although, in this case, it might be warranted.
 
Search WWH ::




Custom Search