Getting Started with Geolocation
Geolocation support is technically not part of HTML5 but resides in a separate geolocation API specification. The latest published version of the specification lives on the W3 website at www.w3.org/TR/geolocation-API/.
Although this book discusses geolocation from the perspective of mobile devices, the API is also available in desktop browsers. Desktop browsers that support the API (IE9+ and recent versions of all other browsers) use a less-accurate IP-address reverse lookup mechanism.
The API defines two mechanisms for grabbing the position: one time and watches. The first type is used when you just need the position once. The second works like setInterval in that it calls the callback repeatedly as the device moves.
Because getting the user’s position via a web page involves privacy concerns, both mechanisms provide a notification to users giving them the power to allow or deny the request to grab the location.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access