W3C Geolocation API


The W3C Geolocation API is an effort by the World Wide Web Consortium 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. The most common sources of location information are IP address, Wi-Fi and Bluetooth MAC address, radio-frequency identification, Wi-Fi connection location, or device Global Positioning System 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.
The Geolocation API is ideally suited to web applications for mobile devices such as personal digital assistants and smartphones. On desktop computers, the W3C Geolocation API works in Firefox since version 3.5, Google Chrome, Opera 10.6, Internet Explorer 9.0, and Safari 5. On mobile devices, it works on Android, iOS, Windows Phone and Maemo. The W3C Geolocation API is also supported by Opera Mobile 10.1 – available for Android and Symbian devices since 24 November 2010.
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 and Opera Mobile for Windows Mobile. However, the Google Gears Geolocation API is incompatible with the W3C Geolocation API and is no longer supported.

Features

The result of W3C Geolocation API will usually give 4 location properties, including latitude and longitude, altitude, and , which all depend on the location sources. In some queries, altitude may yield or return no value.

Location sources

The Geolocation API does not provide the location information. The location information is obtained by a device, which is then served by the API to be brought in browser. Usually geolocation will try to determine a device's position using one of these several methods.
;GPS : This happens for any device which has GPS capabilities. A smartphone with GPS capabilities and set to high accuracy mode will be likely to obtain the location data from this. GPS calculate location information from the satellite signal. It has the highest accuracy; in most Android smartphones, the accuracy can be up to 10 metres.
;Mobile Network Location: Mobile phone tracking is used if a cellphone or wireless modem is used without a GPS chip built in.
;WiFi Positioning System: If WiFi is used indoors, a Wi-Fi positioning system is the likeliest source. Some WiFi spots have location services capabilities.
;IP Address Location: Location is detected based on nearest Public IP Address on a device. The location depends on the IP information available, but in many cases where the IP is hidden behind Internet Service Provider NAT, the accuracy is only to the level of a city, region or even country.

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. 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 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 = =>
const success = =>
const error = =>
const geoOptions = ;