W3C 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.

Uses your system voice; voice and rate in settings.

Snapshot

≈ 3 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

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. 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.

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 uses Google's network location provider.

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). 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.

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 : 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

Text derived from https://en.wikipedia.org/w/index.php?oldid=1338565045 under CC BY-SA 4.0; modifications have been made.

Sources cited in this revision

15 named source(s) extracted from the cited revision. A source with no author is shown by its publication; nothing is invented.