Information Technology Reference
In-Depth Information
Figure 9-1. Android Device location services settings in Android 4.0
These settings are pretty obvious in their function. Turn off GPS satellites, and it won't
be available to any service, including the location-related features of browsers. This is
where our second constraint comes in. Just because the HTML5 specification outlines
the API for geolocation, it doesn't mean the user's browser has implemented all (or any!)
of the features.
Understanding HTML5 Capabilities
It's all fine and dandy for a given device to have a range of location capabilities, but how
do these tie in to your actual web application? The answer comes from the changes
made to the Document Object Model (DOM) with HTML5, which now incorporates an
API to support a range of DOM events specifically for location-related activities. This is a
fairly important subtlety. HTML5 does not implement the location-aware features, per se.
Rather, it incorporates an API specification for how a web browser and a web server or
application can work with location data. This affects you as a developer, as you need to
consider not only what the HTML5 specification says should happen for geolocation
activities, but how each browser has been implemented to actually support these
features. Without getting too far ahead of ourselves, an example would be to understand
what third-party geolocation services a given browser might use if a web application
asks for location.
Detecting Browser Geolocation Support
The basis for pretty much all geolocation activity within a browser is the
navigator.geolocation object. We can use this foundation as a neat shorthand to
determine if the browser has implemented at least the basics of the HTML5 geolocation
specification. Listing 9-1 shows our first code example: a bare-bones HTML and
JavaScript example that determines if a given browser understands a
navigator.geolocation object.
 
Search WWH ::




Custom Search