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.

Download from Wow! eBook <br />

102<br />

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

Figure 4-4. The <strong>HTML</strong>5 Geolocation example application in action<br />

This sample works by using the watchPosition() capability we discussed in the last section. Every<br />

time a new position is sent to us, we will compare it to the last known position and calculate the distance<br />

traveled. This is accomplished using a well-known calculation known as the Haversine formula, which<br />

allows us to calculate distance between two longitude and latitude positions on a sphere. As shown in<br />

Listing 4-6, the Haversine formula tells us the following:

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

Saved successfully!

Ooh no, something went wrong!