25.02.2013 Views

Peter Lubbers - Pro HTML 5 Programming

Pro HTML 5 Programming

Pro HTML 5 Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

88<br />

CHAPTER 4 ■ USING THE <strong>HTML</strong>5 GEOLOCATION API<br />

Latitude and Longitude Coordinates<br />

The location information consists primarily of a pair of latitude and longitude coordinates like the ones<br />

shown in the following example, which shows the coordinates for beautiful Tahoe City, located on the<br />

shore of Lake Tahoe, America’s most beautiful mountain lake:<br />

Latitude: 39.17222, Longitude: -120.13778<br />

In the preceding example, the latitude (the numerical value indicating distance north or south of the<br />

equator is 39.17222) and the longitude (the numerical value indicating distance east or west of<br />

Greenwich, England) is -120.13778.<br />

Latitude and longitude coordinates can be expressed in different ways:<br />

• Decimal format (for example, 39.17222)<br />

• Degree Minute Second (DMS) format (for example, 39° 10' 20')<br />

■ Note When you use the <strong>HTML</strong>5 Geolocation API, coordinates are always returned in decimal degrees.<br />

In addition to latitude and longitude coordinates, <strong>HTML</strong>5 Geolocation always provides the accuracy<br />

of the location coordinates. Additional metadata may also be provided, depending on the device that<br />

your browser is running on. These include altitude, altitudeAccuracy, heading, and speed. If this<br />

additional metadata is not available it will be returned as a null value.<br />

Where Does Location Information Come From?<br />

The <strong>HTML</strong>5 Geolocation API does not specify which underlying technology a device has to use to locate<br />

the application's user. Instead, it simply exposes an API for retrieving location information. What is<br />

exposed, however, is the level of accuracy with which the location was pinpointed. There is no guarantee<br />

that the device's actual location returns an accurate location.<br />

LOCATION, LOCATION<br />

<strong>Peter</strong> says: “Here is a funny example of that. At home, I use a wireless network. I opened the <strong>HTML</strong>5<br />

Geolocation example application shown in this chapter in Firefox and it figured out that I was in<br />

Sacramento (about 75 miles from my actual physical location). Wrong, but not too surprising, because my<br />

Internet Service <strong>Pro</strong>vider (ISP) is located in downtown Sacramento.<br />

Then, I asked my sons, Sean and Rocky, to browse to the same page on their iPod Touch (using the same<br />

Wi-Fi network). In Safari, it looked like they were located in Marysville, California—a town that is located<br />

30 miles from Sacramento. Go figure!”

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!