Chapter 3. Geolocation API in Code

At this point, I am sure there are a lot of you reading this that are thinking to yourself, “Thank you, Mr. Author, for all of that lovely background information on what geolocation is, but can we see how to do this in code, already?” If that is you, then you are in luck, because this chapter is all about coding with the W3C Geolocation API.

The background information in the previous chapters is definitely relevant to our discussion on the Geolocation API itself. Understanding, for example, that the latitude and longitude that we retrieve from the user’s browser is in the WGS 84 datum will come in handy. If you have no idea what I am talking about, go back and read (or re-read) Chapter 2 so that you have a good grasp on the information we are going to be working with.

W3C Geolocation API

The W3C Geolocation API is a specification that provides scripted access to geographical location information associated with the hosting device.[8] It is meant to be a “high-level interface” so that the developer using it does not need to worry about details such as how the location information is being gathered. It does not matter whether the device is using GPS, IP Address, or Cell ID; only the geolocation information itself is important. The one caveat that the specification makes, however, is that there is no guarantee that the location returned from the API is the actual location of the device. This should come as no surprise, given that GPS may not have enough ...

Get HTML5 Geolocation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.