The W3C Geolocation API is an effort by the
World Wide Web Consortium
The World Wide Web Consortium (W3C) is the main international standards organization for the World Wide Web. Founded in 1994 by Tim Berners-Lee, the consortium is made up of member organizations that maintain full-time staff working together in ...
(W3C) to standardize an interface to retrieve the
geographical location information for a client-side device.
It defines a set of objects,
ECMAScript
ECMAScript (; ES) is a standard for scripting languages, including JavaScript, JScript, and ActionScript. It is best known as a JavaScript standard intended to ensure the interoperability of web pages across different web browsers. It is stan ...
standard compliant, that executing in the client application give the client's device location through the consulting of
Location Information Server The location information server, or LIS is a network node originally defined in the National Emergency Number Association i2 network architecture that addresses the intermediate solution for providing e911 service for users of VoIP telephony. Th ...
s, which are transparent for the
application programming interface
An application programming interface (API) is a connection between computers or between computer programs. It is a type of software Interface (computing), interface, offering a service to other pieces of software. A document or standard that des ...
(API). The most common sources of location information are
IP address
An Internet Protocol address (IP address) is a numerical label such as that is assigned to a device connected to a computer network that uses the Internet Protocol for communication. IP addresses serve two main functions: network interface i ...
,
Wi-Fi
Wi-Fi () is a family of wireless network protocols based on the IEEE 802.11 family of standards, which are commonly used for Wireless LAN, local area networking of devices and Internet access, allowing nearby digital devices to exchange data by ...
and
Bluetooth
Bluetooth is a short-range wireless technology standard that is used for exchanging data between fixed and mobile devices over short distances and building personal area networks (PANs). In the most widely used mode, transmission power is li ...
MAC address
A MAC address (short for medium access control address or media access control address) is a unique identifier assigned to a network interface controller (NIC) for use as a network address in communications within a network segment. This use i ...
,
radio-frequency identification
Radio-frequency identification (RFID) uses electromagnetic fields to automatically Automatic identification system, identify and Tracking system, track tags attached to objects. An RFID system consists of a tiny radio transponder called a tag, ...
(RFID), Wi-Fi connection location, or device
Global Positioning System
The Global Positioning System (GPS) is a satellite-based hyperbolic navigation system owned by the United States Space Force and operated by Mission Delta 31. It is one of the global navigation satellite systems (GNSS) that provide ge ...
(GPS) and
GSM
The Global System for Mobile Communications (GSM) is a family of standards to describe the protocols for second-generation (2G) digital cellular networks, as used by mobile devices such as mobile phones and Mobile broadband modem, mobile broadba ...
/
CDMA
Code-division multiple access (CDMA) is a channel access method used by various radio communication technologies. CDMA is an example of multiple access, where several transmitters can send information simultaneously over a single communicatio ...
cell IDs. The location is returned with a given accuracy depending on the best location information source available.
The result of W3C Geolocation API will usually give 4 location properties, including
latitude
In geography, latitude is a geographic coordinate system, geographic coordinate that specifies the north-south position of a point on the surface of the Earth or another celestial body. Latitude is given as an angle that ranges from −90° at t ...
and
longitude
Longitude (, ) is a geographic coordinate that specifies the east- west position of a point on the surface of the Earth, or another celestial body. It is an angular measurement, usually expressed in degrees and denoted by the Greek lett ...
(coordinates), altitude (height), and accuracy
f the position gathered which all depend on the location sources.
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
smartphone
A smartphone is a mobile phone with advanced computing capabilities. It typically has a touchscreen interface, allowing users to access a wide range of applications and services, such as web browsing, email, and social media, as well as multi ...
s. On desktop computers, the W3C Geolocation API works in
Firefox
Mozilla Firefox, or simply Firefox, is a free and open-source web browser developed by the Mozilla Foundation and its subsidiary, the Mozilla Corporation. It uses the Gecko rendering engine to display web pages, which implements curr ...
since version 3.5,
Google Chrome
Google Chrome is a web browser developed by Google. It was first released in 2008 for Microsoft Windows, built with free software components from Apple WebKit and Mozilla Firefox. Versions were later released for Linux, macOS, iOS, iPadOS, an ...
,
Opera
Opera is a form of History of theatre#European theatre, Western theatre in which music is a fundamental component and dramatic roles are taken by Singing, singers. Such a "work" (the literal translation of the Italian word "opera") is typically ...
10.6,
Internet Explorer
Internet Explorer (formerly Microsoft Internet Explorer and Windows Internet Explorer, commonly abbreviated as IE or MSIE) is a deprecation, retired series of graphical user interface, graphical web browsers developed by Microsoft that were u ...
9.0, and Safari 5. On mobile devices, it works on
Android (firmware 2.0+),
iOS
Ios, Io or Nio (, ; ; locally Nios, Νιός) is a Greek island in the Cyclades group in the Aegean Sea. Ios is a hilly island with cliffs down to the sea on most sides. It is situated halfway between Naxos and Santorini. It is about long an ...
,
Windows Phone
Windows Phone (WP) is a discontinued mobile operating system developed by Microsoft Mobile for smartphones as the replacement successor to Windows Mobile and Zune. Windows Phone featured a new user interface derived from the Metro design languag ...
and
Maemo
Maemo is a Linux-based software platform originally developed by Nokia, now developed by the Free software movement, community, for smartphones and Internet tablets. The platform comprises both the Maemo operating system and Software development ...
. The W3C Geolocation API is also supported by Opera Mobile 10.1 – available for Android and
Symbian
Symbian is a discontinued mobile operating system (OS) and computing platform designed for smartphones. It was originally developed as a proprietary software OS for personal digital assistants in 1998 by the Symbian Ltd. consortium. Symbian OS ...
devices (S60 generations 3 & 5) since 24 November 2010. Browsers initially allowed access to the API in insecure contexts, but in the context of Secure Contexts, browsers, e.g., Chrome, 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
Windows Mobile is a discontinued mobile operating system developed by Microsoft for smartphones and personal digital assistants (PDA). Designed to be the portable equivalent of the Windows desktop OS in the emerging Mobile device, mobile/port ...
. However, the Google Gears Geolocation API is incompatible with the W3C Geolocation API and is no longer supported.
Location sources
The Geolocation API does not provide the location information. The location information is obtained by a device (such as a smartphone, PC or modem), 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 (Global Positioning System): 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
Mobile phone tracking is a process for identifying the location of a mobile phone, whether stationary or moving. Localization may be affected by a number of technologies, such as the multilateration of radio signals between (several) cell towers ...
is used if a cellphone or wireless modem is used without a GPS chip built in.
; Wi-Fi Positioning System: If Wi-Fi is used indoors, a
Wi-Fi positioning system
Wi-Fi positioning system (WPS, WiPS or WFPS) is a geolocation system that uses the characteristics of nearby Wi‑Fi access points to discover where a device is located.
It is used where satellite navigation such as GPS is inadequate due to vari ...
is the likeliest source. Some Wi-Fi spots have location services capabilities.
; IP Address Location: Location is detected based on the nearest public IP address on a device (which can be a computer, the router it is connected to, or the
Internet Service Provider
An Internet service provider (ISP) is an organization that provides a myriad of services related to accessing, using, managing, or participating in the Internet. ISPs can be organized in various forms, such as commercial, community-owned, no ...
(ISP) the router uses). The location depends on the IP information available, but in many cases where the IP is hidden behind an ISP
network address translation
Network address translation (NAT) is a method of mapping an IP address space into another by modifying network address information in the IP header of packets while they are in transit across a traffic Router (computing), routing device. The te ...
, 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 (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
JSON (JavaScript Object Notation, pronounced or ) is an open standard file format and electronic data interchange, data interchange format that uses Human-readable medium and data, human-readable text to store and transmit data objects consi ...
) 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
Contextual advertising (also called contextual targeting) is a form of targeted digital advertising. Contextual advertising is also called "In-Text" advertising or "In-Context" technology. Contextual targeting involves the use of linguistic fact ...
and preventing identity theft.
Example code
Simple
JavaScript
JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior.
Web browsers have ...
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 = (position) =>
const error = (error) =>
const geoOptions = ;
See also
*
Local search (Internet)
Local search is the use of specialized Internet search engines that allow users to submit geographically constrained searches against a structured database of local business listings. Typical local search queries include not only information abou ...
*
Location-based service
Location-based service (LBS) is a general term denoting software service (economics), services which use geographic data and information to provide services or information to users. LBS can be used in a variety of contexts, such as health, indoor ...
References
External links
W3C Geolocation API Specification
{{Web interfaces
Application programming interfaces
HTML5
Internet geolocation
Location-based software
Web standards