HTML and CSS Reference
In-Depth Information
Chapter 23
Locating via Geolocation
What's in This Chapter?
• Locating users with geolocation
• Drawing static maps
• Drawing interactive maps
Wrox.com Code Downloads for This Chapter
You can find the wrox.com code downloads for this chapter at www.wrox.com/rem-
title.cgi?isbn=9781118301326 on the Download Code tab. The code is in the Chapter 23 download and indi-
vidually named according to the names throughout the chapter.
Introduction
Up to this point this topic has treated the word mobile as referring primarily to a form factor (small screen) and
an input mechanism (touchscreen). A third major aspect to mobile devices is that they are portable, and thus
the user's location can be made into an interesting aspect of game play. This chapter examines the support to
determine a device's location, known as geolocation , which is available in one of the HTML5 families of spe-
cifications, and discusses how you can use it in games.
Getting Started with Geolocation
Geolocation support is technically not part of HTML5 but resides in a separate geolocation API specification.
The latest published version of the specification lives on the W3 website at www.w3.org/TR/geolocation-API/ .
Although this topic discusses geolocation from the perspective of mobile devices, the API is also available
in desktop browsers. Desktop browsers that support the API (IE9+ and recent versions of all other browsers)
use a less-accurate IP-address reverse lookup mechanism.
The API defines two mechanisms for grabbing the position: one time and watches. The first type is used
when you just need the position once. The second works like setInterval in that it calls the callback re-
peatedly as the device moves.
Because getting the user's position via a web page involves privacy concerns, both mechanisms provide a
notification to users giving them the power to allow or deny the request to grab the location.
Search WWH ::




Custom Search