HTML and CSS Reference
Geolocation and Mapping
This chapter will demonstrate two technologies that provide powerful features that enable you to easily create
some very useful web sites. Geolocation provides a standardized API that is used to determine the client's
location. Mapping technology adds the ability to display this location on a map along with other points of
interest. Together, these form a platform that has many useful applications.
In this chapter you'll use the geolocation API to find your current position. The accuracy of that position will
vary greatly depending on available hardware and the environment. However, HTML5 defines a standard API
that is used on all devices so you can provide device-independent solutions.
Just knowing your location in terms of latitude and longitude is not very helpful. To put this data to use,
you'll use the Bing Maps API to display that location on a map. Then you can map additional points of interest
and see them in relation to your current location.
While not technically part of the HTML5 specification, the WC3 has defined a standard API for accessing
geolocation information, which is supported by all major current browser versions. The technology that
determines the location, however, varies greatly depending on the device capabilities and the client's
Surveying Geolocation Technologies
There are several technologies that can be used to determine the current location, including:
Global Positioning Satellites (GPS) - GPS communicates with satellites to determine the
current location with extremely high accuracy, particularly in rural areas. Tall buildings in
an urban area can affect the accuracy but in most cases GPS provides very good results.
The biggest limitation is that this doesn't work indoors very well. To use GPS, the device
must have specific GPS hardware, but this is becoming increasingly common on mobile
Wi-Fi Positioning - Wi-Fi networks have a relatively short range and systems such as
Skyhook Wireless maintain a large database of Wi-Fi networks and their locations.
Simply being connected to a Wi-Fi network will give a pretty good idea of where you
are. Often, however, you may be within range of multiple networks and the system can
use triangulation to determine the location with even greater accuracy. Of course, this
requires that you have a Wi-Fi enabled device and doesn't work in rural areas where there
are no Wi-Fi networks.