W3C Geolocation API

Short description: Javascript API to geolocate devices

Geolocation APIFirst published| 22 December 2008; 17 years ago (2008-12-22)[1][2]

|

Latest version| W3C Recommendation
1 September 2022; 3 years ago (2022-09-01)[3]
Organization|

* W3C
* Google

Committee| Geolocation Working Group[3]
Editors| Andrei Popescu[3]
Domain| Geographical location information
Website| www.w3.org/TR/geolocation-API/

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.

## Contents

* 1 Deployment in web browsers
* 2 Implementation
* 2.1 Example code
* 3 See also
* 4 References
* 5 External links

## 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][5]

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,[6] Opera 10.6,[7] Internet Explorer 9.0,[8] 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.[9] Browsers initially allowed access to the API in insecure contexts, but in the context of Secure Contexts,[10] browsers, e.g., Chrome,[11] 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[12] uses Google's network location provider.[5] 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 = () => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error, geoOptions);
} else {
console.log("Geolocation services are not supported by your web browser.");

const success = (position) => {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
const altitude = position.coords.altitude;
const accuracy = position.coords.accuracy;
console.log(`lat: ${latitude} long: ${longitude}`);

const error = (error) => {
console.log(`Unable to retrieve your location due to ${error.code}: ${error.message}`);

const geoOptions = {
enableHighAccuracy: true,
maximumAge: 30000,
timeout: 27000

## See also

* Internet geolocation
* Local search (Internet)
* Location-based service

## References

1. ↑ "Geolocation API Specification 2nd Edition Publication History". W3C. n.d.. https://www.w3.org/standards/history/geolocation-API.
2. ↑ Popescu, Andrei (22 December 2008). "Geolocation API Specification". W3C Geolocation Working Group. https://www.w3.org/TR/2008/WD-geolocation-API-20081222/.
3. ↑ 3.0 3.1 3.2 3.3 Cáceres, Marcos; Grant, Reilly (1 September 2022). "Geolocation API Specification". W3C Geolocation Working Group. https://www.w3.org/TR/2008/WD-geolocation-API-20081222/.
4. ↑ "Geolocation API: Gears API: Google Code". 9 July 2009. https://code.google.com/apis/gears/api_geolocation.html.
5. ↑ 5.0 5.1 "GeolocationAPI - gears - Provides the geolocation of a device running a Gears-enabled web browser. - Improving Your Web Browser - Google Project Hosting". Google Code. n.d.. https://code.google.com/apis/gears/geolocation_network_protocol.html.
6. ↑ "A new Chrome stable release: Welcome, Mac and Linux!". 25 May 2010. https://chrome.blogspot.com/2010/05/new-chrome-stable-release-welcome-mac.html.
7. ↑ Kleinhout, Huib (1 July 2021). "Opera 10.60 goes final". My Opera. Opera Software. http://my.opera.com/desktopteam/blog/2010/07/01/opera-10-60-goes-final.
8. ↑ ieblog (17 February 2011). "W3C Geolocation API in IE9 - IEBlog - Site Home - MSDN Blogs". http://blogs.msdn.com/b/ie/archive/2011/02/17/w3c-geolocation-api-in-ie9.aspx.
9. ↑ Opera.com (25 November 2010). "Opera speeds up Symbian browsing". http://www.opera.com/press/releases/2010/11/24/.
10. ↑ "Secure Contexts". https://www.w3.org/TR/secure-contexts/Overview.html.
11. ↑ "Intent to Remove: Insecure origin usage of geolocation". https://groups.google.com/a/chromium.org/g/blink-dev/c/ylz0Zoph76A/m/jaMAcld6BQAJ.
12. ↑ "Does Firefox share my location with websites? | Mozilla Support". Mozilla Firefox. Mozilla. n.d.. https://support.mozilla.org/en-US/kb/does-firefox-share-my-location-websites?redirectslug=does-firefox-share-my-location-web-sites&redirectlocale=en-US.
13. ↑ "WebScanNotes.com: W3C Geolocation API". WebScanNotes. n.d.. http://webscannotes.com/?page_id=425.
14. ↑ King, Kevin F. (8 June 2010). "Personal Jurisdiction, Internet Commerce, and Privacy: The Pervasive Legal Consequences of Modern Geolocation Technologies". https://papers.ssrn.com/sol3/papers.cfm?abstract_id=1622411.

## External links

* W3C Geolocation API Specification

* v
* t
* e

World Wide Web Consortium (W3C)

Products and
standards|

| Recommendations|

* ActivityPub
* ARIA
* Canonical XML
* CDF
* CSS
* DOM
* Geolocation API
* HTML (HTML5)
* ITS
* JSON-LD
* Linked Data Notifications
* MathML
* Micropub
* OWL
* PLS
* RDF
* RDF Schema
* SISR
* SKOS
* SMIL
* SOAP
* SRGS
* SRI
* SSML
* SVG
* SCXML
* SHACL
* SPARQL
* Timed text
* VoiceXML
* Web storage
* WSDL
* Webmention
* WebSub
* XForms
* XHTML
* XHTML+RDFa
* XInclude
* XLink
* XML
* XML Base
* XML Encryption
* XML Events
* XML Information Set
* XML namespace
* XML Schema
* XML Signature
* XOP
* XPath
* XPath 2.0
* XPointer
* XProc
* XQuery
* XSL
* XSL-FO
* XSLT (elements)

|

Notes|

* IndieAuth
* JF2
* Post Type Discovery
* XAdES
* XHTML+SMIL
* XUP

Working drafts|

* CCXML
* CURIE
* EME
* InkML
* MSE
* RIF
* SMIL Timesheets
* sXBL
* XFDL
* XFrames
* XBL
* XMLHttpRequest

Guidelines|

* Web Content Accessibility Guidelines

Initiative|

* Multimodal Interaction Activity (MMI)
* Markup Validation Service
* Web Accessibility Initiative
* WebPlatform

Deprecated|

* C-HTML
* HDML
* JSSS
* PGML
* VML
* XHTML+MathML+SVG

Obsoleted|

* P3P

Organizations|

* Advisory Committee (AC)
* World Wide Web Foundation

Elected groups|

* Advisory Board (AB)

Working groups|

* CSS
* Geolocation
* Social Web
* SVG
* Web Hypertext Application Technology (WHATWG)
* Web Platform

Community groups|

* Web Incubator Community Group (WICG)

Closed groups|

* Device Description (DDWG)
* HTML

Software|

* CERN httpd
* Libwww

Browsers|

* Line Mode (1990–)
* Arena (1993–98)
* Agora (1994–97)
* Argo (1994–97)
* Amaya (browser/editor, 1996–2012)

Conferences|

* International World Wide Web Conference (IW3C)
* Steering Committee (IW3C2)
* First conference ("WWW1", 1994)

* v
* t
* e

Web interfaces

Server-side|

| Protocols|

* HTTP
* CGI
* SCGI
* FCGI
* AJP
* WSRP
* WebSocket

|

Server APIs|

* C NSAPI
* C ASAPI
* C ISAPI
* COM ASP
* Java servlet
* container
* CLI OWIN
* ASP.NET Handler
* Python WSGI
* Ruby Rack
* JavaScript JSGI
* Perl PSGI
* Lua WSAPI
* Portlet
* container

Apache modules|

* mod include
* mod jk
* mod lisp
* mod mono
* mod parrot
* mod perl
* mod php
* mod proxy
* mod python
* mod wsgi
* mod ruby
* Phusion Passenger

Topics|

* Web resource vs. Web service
* Open API
* Webhook
* Application server
* comparison
* Scripting

Client-side|

| Browser APIs|

* C NPAPI
* LiveConnect
* XPConnect
* C NPRuntime
* C PPAPI
* NaCl
* ActiveX
* BHO
* XBAP

|

Web APIs|

| W3C|

* Audio
* Canvas
* CORS
* DOM
* DOM events
* EME
* File
* Geolocation
* IndexedDB
* MSE
* SSE
* SVG
* Video
* WebAuthn
* WebRTC
* WebSocket
* Web messaging
* Web storage
* Web worker
* XMLHttpRequest
* WebAssembly

|

Khronos|

* WebCL
* WebGL

Others|

* Gears
* Web SQL Database (formerly W3C)
* WebUSB

Topics|

* Ajax and Remote scripting vs. DHTML
* Mashup
* Web IDL
* Scripting

Topics|

* Dynamic web page
* Web standards
* Rich web application
* Web API security
* Web application
* Web framework

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/W3C Geolocation API. Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=W3C_Geolocation_API&oldid=4155581"
*[W3C]: World Wide Web Consortium
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template