W3C Geolocation API explained

Geolocation API
First Published:[1] [2]
Version:W3C Recommendation
Committee:Geolocation Working Group
Editors:Andrei Popescu
Domain:Geographical location information

The W3C Geolocation API is an effort by the World Wide Web Consortium (W3C) to standardize an interface to retrieve the geographical location information for a client-side device.[3] It defines a set of objects, ECMAScript standard compliant, that executing in the client application give the client's device location through the consulting of Location Information Servers, which are transparent for the application programming interface (API). The most common sources of location information are IP address, available Wi-Fi and Bluetooth networks, radio-frequency identification (RFID), Wi-Fi connection location, or device Global Positioning System (GPS) and GSM/CDMA cell IDs. The location is returned with a given accuracy depending on the best location information source available.

Deployment in web browsers

Web pages can use the Geolocation API directly if the web browser implements it. Historically, some browsers could gain support via the Google Gears plugin, but this was discontinued in 2010 and the server-side API it depended on stopped responding in 2012.[4]

The Geolocation API is ideally suited to web applications for mobile devices such as smartphones. On desktop computers, the W3C Geolocation API works in Firefox since version 3.5, Google Chrome,[5] Opera 10.6,[6] Internet Explorer 9.0,[7] and Safari 5. On mobile devices, it works on Android (firmware 2.0+), iOS, Windows Phone and Maemo. The W3C Geolocation API is also supported by Opera Mobile 10.1 – available for Android and Symbian devices (S60 generations 3 & 5) since 24 November 2010.[8] Browsers initially allowed access to the API in insecure contexts, but in the context of Secure Contexts,[9] browsers, e.g., Chrome,[10] now generally require a secure connection.

Google Gears provided geolocation support for older and non-compliant browsers, including Internet Explorer 7.0+ as a Gears plugin, and Google Chrome which implemented Gears natively. It also supported geolocation on mobile devices as a plugin for the Android browser (pre version 2.0) and Opera Mobile for Windows Mobile. However, the Google Gears Geolocation API is incompatible with the W3C Geolocation API and is no longer supported.

Implementation

Though the implementation is not specified, W3C Geolocation API is built on extant technologies, and is heavily influenced by Google Gears Geolocation API. Example: Firefox's Geolocation implementation[11] uses Google's network location provider.[12] Google Gears Geolocation works by sending a set of parameters that could give a hint as to where the user's physical location is to a network location provider server, which is by default the one provided by Google (code.l.google.com).[13] Some of the parameters are lists of sensed mobile cell towers and Wi-Fi networks, all with sensed signal strengths. These parameters are encapsulated into a JavaScript Object Notation (JSON) message and sent to the network location provider via HTTP POST. Based on these parameters, the network location provider can calculate the location. Common uses for this location information include enforcing access controls, localizing and customizing content, analyzing traffic, contextual advertising and preventing identity theft.[14]

Example code

Simple JavaScript code that checks if the browser has the Geolocation API implemented and then uses it to get the current position of the device. this code creates a function which can be called on HTML using <body onload="geoFindMe">:const geoFindMe = =>

const success = (position) =>

const error = (error) =>

const geoOptions = ;

See also

External links

Notes and References

  1. Web site: Geolocation API Specification 2nd Edition Publication History . W3C . n.d.. 21 April 2021 .
  2. Web site: Geolocation API Specification . Andrei . Popescu . W3C Geolocation Working Group . 22 December 2008 . 21 April 2021 .
  3. Web site: Geolocation API Specification . Marcos . Cáceres . Reilly . Grant . W3C Geolocation Working Group . 1 September 2022 . 8 February 2024 .
  4. Web site: Geolocation API: Gears API: Google Code . https://web.archive.org/web/20120214212239/https://code.google.com/apis/gears/api_geolocation.html. Google Code . 9 July 2009 . 14 February 2012 . 21 April 2021 .
  5. Web site: A new Chrome stable release: Welcome, Mac and Linux!. Google Chrome Blog . 25 May 2010 . 21 April 2021 .
  6. Web site: Opera 10.60 goes final. https://web.archive.org/web/20111109061925/http://my.opera.com/desktopteam/blog/2010/07/01/opera-10-60-goes-final. Huib. Kleinhout . . . 1 July 2021 . 9 November 2011 . 21 April 2021 .
  7. Web site: W3C Geolocation API in IE9 - IEBlog - Site Home - MSDN Blogs. dead. https://web.archive.org/web/20110219033657/http://blogs.msdn.com/b/ie/archive/2011/02/17/w3c-geolocation-api-in-ie9.aspx. ieblog. IEBlog. 17 February 2011. 19 February 2011. 21 April 2021 .
  8. Web site: Opera speeds up Symbian browsing. https://web.archive.org/web/20111104005142/http://www.opera.com/press/releases/2010/11/24/. Opera.com. 25 November 2010. 4 November 2011. 21 April 2021 .
  9. Web site: Secure Contexts . 13 October 2022 . W3.org .
  10. Web site: Intent to Remove: Insecure origin usage of geolocation . 13 October 2022 . Groups.Google.com .
  11. Web site: Does Firefox share my location with websites? Mozilla Support. Mozilla Firefox. Mozilla Firefox. Mozilla. n.d.. 21 April 2021.
  12. Web site: GeolocationAPI - gears - Provides the geolocation of a device running a Gears-enabled web browser. - Improving Your Web Browser - Google Project Hosting. dead. https://web.archive.org/web/20151222162645/https://code.google.com/p/gears/wiki/GeolocationAPI. Google Code. 22 December 2015. n.d.. 21 April 2021.
  13. Web site: WebScanNotes.com: W3C Geolocation API. dead. https://web.archive.org/web/20121112035756/http://webscannotes.com/geolocation-api/. WebScanNotes. n.d.. 12 November 2012. 21 April 2021.
  14. Web site: Personal Jurisdiction, Internet Commerce, and Privacy: The Pervasive Legal Consequences of Modern Geolocation Technologies. 1622411 . Kevin F.. King. 8 June 2010. 9 June 2010. 21 April 2021.