HTML and CSS Reference
In-Depth Information
Once you allow the page to use your location data, you should see an Alert dialog containing the latitude and longit-
ude coordinates for your current location as shown in Figure 13-3. This Alert dialog is generated by the code you ad-
ded in Step 5.
Map data 2012 © Google
Figure 13-3 An alert dialog showing my current position.
Calculating the Distance Between Two Sets of GPS
Now that you can successfully capture a user's location data, it's time to write code that will calculate the distance
between the user and each restaurant location.
To calculate the distance between two sets of GPS coordinates, you use the Haversine formula. This formula calcu-
lates the distance between two points on the earth's surface, taking into account the curvature of the earth (which
makes a big difference for two points that are far away from each other). The geo.js file that you included earlier
in this chapter contains a JavaScript function that calculates distances using an implementation of the Haversine for-
mula. This function takes four parameters: the latitude and longitude values of the two locations.
Search WWH ::

Custom Search