539
Chapter 14 Making your HTML location-aware
CHAPTER 14 Making your HTML location-aware
T
he Geolocation application programming interface (API) provides an interface with
device location information such as latitude and longitude; you can use the Geolocation
API to make your applications location-aware. Imagine creating an application that enables
the user to enter favorite information, such as where to drink coffee or shop for comput-
ers. As the user gets close to a favorite place such as a coffee shop or a computer store, the
device displays a map with the location. Maybe the coffee shop could provide incentives to
motivate the user to stop by for a quick cup of coffee.
The API is generic enough to interface with many underlying location information
sources such as the Global Positioning System (GPS) and locations inferred from network
signals such as IP address, radio frequency identification (RFID), Wi-Fi and Bluetooth MAC
addresses, and cellular IDs and from user input. No guarantee is given that the API returns
the device’s actual location, and the accuracy can vary widely. Increasingly, mobile devices
are shipped with GPS in addition to accelerometer and compass. These sensors can provide
great accuracy to the Geolocation API.
The Geolocation API is being standardized by the Geolocation Working Group, which
is separate from the HTML5 Working Group. Therefore, the Geolocation API is not part
of HTML5, although support for geolocation is being added to browsers in parallel with
HTML5.
The API is designed to enable both one-shot position requests and repeated position
updates. Lesson 1, “Basic positioning,” covers one-shot queries; Lesson 2, “Monitored posi-
tioning,” covers repeated position updates.
Lessons in this chapter:
■■Lesson 1: Basic positioning 540
■■Lesson 2: Monitored positioning 546