Information Technology Reference
In-Depth Information
Dealing with the Four Corners of Android's Geolocation
World
Our initial sample application introduces some of the key building blocks of almost all
web applications that utilize geolocation. To round out the world of geolocation, we
need to address the four questions of Where am I? , What am I? , What could possibly go
wrong? , and Where am I going?
Where Am I?
We've already touched on the fundamentals of determining where a device happens to
be, with our use of the position.coords.latitude and position.coords.longitude data
members in our earlier example. You might be thinking that there's not much more to
determining location than that, but there are a few additional data points you should
consider.
While latitude and longitude can tell you if you're in Hawaii or The Himalayas, you'll
probably agree that there's another dimension you care about in both of those locations:
altitude! The HTML5 specification includes a position.coords.altitude data member to
provide an elevation above notional sea level. Note that support for this is quite patchy,
such that even the Android emulator and its browser fail to support it in many releases
of the Android Development Tools (ADT).
Along with latitude, longitude, and altitude, you might be concerned with how accurate a
reading you've been given. We introduced four possible location mechanisms at the
start of the chapter, and each of these has varying levels of accuracy. Two additional
data members are available, position.coords.accuracy and
position.coords.altitudeAccuracy , to provide the margin of error for any geolocation
data provided.
Interestingly, there's no direct method by which you can determine which location
mechanism was used to provide your coordinates. You can infer that it was GPS if you
interrogate another data value, position.coords.satellites , which, if supported by
your browser and device, will return the number of satellites used to provide a GPS fix.
The only problem with this is that if your device lacks GPS support, or fails to get a GPS
fix, both situations will return NULL. So you'll be left in an ambiguous state as to what
determined the lack of satellite count.
What Am I?
We've already largely dealt with the best way of answering the What am I? question. The
HTML5 geolocation specification doesn't provide exhaustive ways of determining what
particular hardware exists on a device. The best way to approach the question is using
the supportsGeo() function, or one like it, that we introduced in the preceding section.
This turns our question into one of: What am I? A device and browser combination that
supports geolocation or not?
 
Search WWH ::




Custom Search