W3C Geolocation API: Difference between revisions

Content deleted Content added
Bender the Bot (talk | contribs)
 
(34 intermediate revisions by 23 users not shown)
Line 1:
{{Short description|Javascript API to geolocate devices}}
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.<ref>{{cite web |url=https://www.w3.org/TR/geolocation-API/ |title=Geolocation API Specification: W3C Recommendation 24 October 2013 |first=Andrei (editor, Google Inc.) |last=Popescu |publisher=W3C |accessdate=4 February 2016}}</ref> 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 Server]]s, which are transparent for the [[application programming interface]] (API). The most common sources of ___location information are [[IP address]], [[Wi-Fi]] and [[Bluetooth]] [[MAC address]], [[radio-frequency identification]] (RFID), Wi-Fi connection ___location, or device [[Global Positioning System]] (GPS) and [[GSM]]/[[CDMA2000|CDMA]] cell IDs. The ___location is returned with a given accuracy depending on the best ___location information source available.
{{Use dmy dates|date=MarchJune 20112020}}
{{Infobox technology standard
| title = Geolocation API
| long_name =
| image =
| caption =
| first_published = {{Start date and age|df=yes|2008|12|22}}<ref name="geolocation-spec-hist">{{Cite web|url=https://www.w3.org/standards/history/geolocation-API|title=Geolocation API Specification 2nd Edition Publication History - W3C|date=n.d.|access-date=2021-04-21}}</ref><ref name="geolocation-spec-20081222">{{cite web|url=https://www.w3.org/TR/2008/WD-geolocation-API-20081222/|title=Geolocation API Specification|first=Andrei|last=Popescu|website=W3C|publisher=Geolocation Working Group|date=2008-12-22|access-date=2021-04-21}}</ref>
| version = W3C Recommendation
| version_date = {{Start date and age|df=yes|2022|09|01}}<ref name="geolocation-spec" />
| preview =
| preview_date =
| organization = {{Plainlist|
* {{abbr|[[World Wide Web Consortium|W3C]]|World Wide Web Consortium}}
* [[Google]]
}}
| committee = Geolocation Working Group<ref name="geolocation-spec" />
| editors = Andrei Popescu<ref name="geolocation-spec" />
| authors =
| base_standards =
| related_standards =
| abbreviation =
| ___domain = [[Geographical ___location information]]
| license =
| website = {{URL|https://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.<ref name="geolocation-spec">{{cite web |url=https://www.w3.org/TR/2008/WD-geolocation-API-20081222/ |title=Geolocation API Specification: W3C Recommendation 24 October 2013 |firstfirst1=Andrei (editor, Google Inc.) Marcos|lastlast1=Popescu Cáceres|publisherfirst2=Reilly|last2=Grant|website=W3C |accessdatepublisher=4Geolocation FebruaryWorking 2016Group|date=2022-09-01|access-date=2024-02-08}}</ref> 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 Server]]s, which are transparent for the [[application programming interface]] (API). The most common sources of ___location information are [[IP address]], [[Wi-Fi]] and [[Bluetooth]] [[MAC address]], [[radio-frequency identification]] (RFID), Wi-Fi connection ___location, or device [[Global Positioning System]] (GPS) and [[GSM]]/[[CDMA2000|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]] [[plug-in (computing)|plugin]], but this was discontinued in 2010 and the server-side API it depended on stopped responding in 2012.<ref>{{cite web |url=https://code.google.com/apis/gears/api_geolocation.html |title=Geolocation API: Gears API: Google Code |date=9 July 2009}}</ref><ref>[https://code.google.com/p/gears/wiki/GeolocationAPI GeolocationAPI - gears - Provides the geolocation of a device running a Gears-enabled web browser. - Improving Your Web Browser - Google Project Hosting]. Code.google.com. Retrieved on 2014-06-01.</ref>
 
The result of W3C Geolocation API will usually give 4 ___location properties, including [[latitude]] and [[longitude]] (coordinates), altitude (height), and [accuracy [of the position gathered], which all depend on the ___location sources.{{Citation needed|date=February In some queries, altitude may yield or return no value.2023}}
The Geolocation API is ideally suited to web applications for mobile devices such as [[personal digital assistant]]s (PDA) and [[smartphone]]s. On desktop computers, the W3C Geolocation API works in [[Firefox]] since version 3.5, [[Google Chrome]],<ref>{{cite web |url=http://chrome.blogspot.com/2010/05/new-chrome-stable-release-welcome-mac.html |title=A new Chrome stable release: Welcome, Mac and Linux! |date=25 May 2010}}</ref> [[Opera (web browser)|Opera]] 10.6,<ref>{{cite web |url=http://my.opera.com/desktopteam/blog/2010/07/01/opera-10-60-goes-final |title=Opera 10.60 goes final |first=Huib |last=Kleinhout |date=1 July 2010 |work=[[My Opera]] |publisher=[[Opera Software]] |accessdate=2 July 2010}}</ref> [[Internet Explorer]] 9.0,<ref>{{cite web|title=W3C Geolocation API in IE9|url=http://blogs.msdn.com/b/ie/archive/2011/02/17/w3c-geolocation-api-in-ie9.aspx}}</ref> and Safari 5. On mobile devices, it works on [[Android (operating system)|Android]] (firmware 2.0+), [[iOS (Apple)|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 November 24, 2010.<ref>{{cite web|url=http://www.opera.com/press/releases/2010/11/24/|author=Opera.com|title=Opera Mobile 10.1 for Nokia smartphones goes final |date=2010-11-25}}</ref>
 
== Deployment in web browsers ==
[[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 (operating system)|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.
Web pages can use the Geolocation API directly if the web browser implements it. Historically, some browsers could gain support via the [[Google Gears]] [[plug-in (computing)|plugin]], but this was discontinued in 2010 and the server-side API it depended on stopped responding in 2012.<ref>{{cite web |url=https://code.google.com/apis/gears/api_geolocation.html |archive-url=https://web.archive.org/web/20120214212239/https://code.google.com/apis/gears/api_geolocation.html|title=Geolocation API: Gears API: Google Code |website=Google Code |date=9 July 2009 |archive-date=2012-02-14 |access-date=2021-04-21 }}</ref><ref>[https:// name="code.-google.com/p/gears/wiki/GeolocationAPI GeolocationAPI - gears gear- Provides the geolocation of a device running a Gearsgeo-enabledapi" web browser. - Improving Your Web Browser - Google Project Hosting]. Code.google.com. Retrieved on 2014-06-01.</ref>
 
The Geolocation API is ideally suited to web applications for mobile devices such as [[personal digital assistant]]s (PDA) and [[smartphone]]s. On desktop computers, the W3C Geolocation API works in [[Firefox]] since version 3.5, [[Google Chrome]],<ref>{{cite web |url=httphttps://chrome.blogspot.com/2010/05/new-chrome-stable-release-welcome-mac.html |title=A new Chrome stable release: Welcome, Mac and Linux!|website=Google Chrome Blog |date=25 May 2010 |access-date=2021-04-21 }}</ref> [[Opera (web browser)|Opera]] 10.6,<ref>{{cite web |url=http://my.opera.com/desktopteam/blog/2010/07/01/opera-10-60-goes-final |archive-url=https://web.archive.org/web/20111109061925/http://my.opera.com/desktopteam/blog/2010/07/01/opera-10-60-goes-final|title=Opera 10.60 goes final |first=Huib |last=Kleinhout |date=1 July 2010 |work=[[My Opera]] |publisher=[[Opera Software]] |accessdatedate=22021-07-01 July|archive-date=2011-11-09 |access-date=2021-04-21 2010}}</ref> [[Internet Explorer]] 9.0,<ref>{{cite web|title=W3C Geolocation API in IE9 - IEBlog - Site Home - MSDN Blogs|url=http://blogs.msdn.com/b/ie/archive/2011/02/17/w3c-geolocation-api-in-ie9.aspx|url-status=dead|archive-url=https://web.archive.org/web/20110219033657/http://blogs.msdn.com/b/ie/archive/2011/02/17/w3c-geolocation-api-in-ie9.aspx|author=ieblog|website=IEBlog|date=2011-02-17|archive-date=2011-02-19|access-date=2021-04-21 }}</ref> and Safari 5. On mobile devices, it works on [[Android (operating system)|Android]] (firmware 2.0+), [[iOS (Apple)|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 24, 2010.<ref>{{cite web|url=http://www.opera.com/press/releases/2010/11/24/ |archive-url=https://web.archive.org/web/20111104005142/http://www.opera.com/press/releases/2010/11/24/|author=Opera.com|title=Opera Mobilespeeds up Symbian browsing|date=2010-11-25|archive-date=2011-11-04|access-date=2021-04-21 }}</ref> Browsers initially allowed access to the API in insecure contexts, but in the context of Secure Contexts,<ref>{{Cite web |title=Secure Contexts |url=https://www.w3.org/TR/secure-contexts/Overview.html |access-date=2022-10-13 |website=W3.1org for}}</ref> Nokiabrowsers, smartphonese.g., goesChrome,<ref>{{Cite finalweb |title=Intent to Remove: Insecure origin usage of geolocation |url=https://groups.google.com/a/chromium.org/g/blink-dev/c/ylz0Zoph76A/m/jaMAcld6BQAJ |access-date=20102022-1110-2513 |website=Groups.Google.com }}</ref> now generally require a secure connection.
==Features==
 
The result of W3C Geolocation API will usually give 4 ___location properties, including latitude and longitude (coordinates), altitude (height), and [accuracy of the position gathered], which all depend on the ___location sources. In some queries, altitude may yield or return no value.
[[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 (operating system)|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.
 
==Location sources==
{{Unreferenced section|date=January 2022}}
 
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 [[Global Positioning System|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 Wi-Fi Positioning System: If WiFiWi-Fi is used indoors, a [[Wi-Fi positioning system]] is the likeliest source. Some WiFiWi-Fi spots have ___location services capabilities.
; IP Address Location: Location is detected based on the nearest Publicpublic IP Addressaddress on a device (which can be a computer, the router it is connected to, or the [[Internet Service Provider]] (ISP) the router uses). The ___location depends on the IP information available, but in many cases where the IP is hidden behind Internetan ServiceISP Provider[[network address NATtranslation]], 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<ref>{{cite web |url=https://support.mozilla.org/en-US/kb/does-firefox-share-my-___location-websites?redirectslug=does-firefox-share-my-___location-web-sites&redirectlocale=en-US|title=Does Firefox share my ___location with websites? {{!}} Mozilla Support|work=Mozilla Firefox|author-link=Mozilla Firefox|publisher=Mozilla|date=n.d.|access-date=2021-04-21}}</ref> uses Google's network ___location provider.<ref name="code-google-gear-geo-api">{{cite web |url=https://code.google.com/apis/gears/geolocation_network_protocol.html|url-status=dead|archive-url=https://web.archive.org/web/20151222162645/https://code.google.com/p/gears/wiki/GeolocationAPI|title=GeolocationAPI - gears - Provides the geolocation of a device running a Gears-enabled web browser. - Improving Your Web Browser - Google Project Hosting|work=Google Code|archive-date=2015-12-22|date=n.d.|access-date=2021-04-21}}</ref> 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).<ref>{{cite web |url=http://webscannotes.com/?page_id=425 |url-status=dead|archive-url=https://web.archive.org/web/20121112035756/http://webscannotes.com/geolocation-api/|title=WebScanNotes.com: W3C Geolocation API |work=WebScanNotes|date=n.comd.|archive-date=2012-11-12|access-date=2021-04-21}}</ref> 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.<ref>{{cite web |url=https://papers.ssrn.com/sol3/papers.cfm?abstract_id=1622411|ssrn=1622411 |title=Personal Jurisdiction, Internet Commerce, and Privacy: The Pervasive Legal Consequences of Modern Geolocation Technologies |first=Kevin F. |last=King |date=8 June 2010-06-08|publication-date=2010-06-09|access-date=2021-04-21}}</ref>
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<ref>{{cite web |url=https://www.mozilla.org/en-US/firefox/geolocation/ |title=Location-Aware Browsing |work=Mozilla Firefox |publisher=Mozilla}}</ref> uses Google's network ___location provider.<ref>{{cite web |url=https://code.google.com/apis/gears/geolocation_network_protocol.html |title=Geolocation API Network Protocol: Gears API |work=Google Code |publisher=Google |accessdate=8 August 2011}}</ref>
 
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).<ref>{{cite web |url=http://webscannotes.com/?page_id=425 |title=WebScanNotes.com: W3C Geolocation API |work=WebScanNotes.com}}</ref> 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.<ref>{{cite web |ssrn=1622411 |title=Personal Jurisdiction, Internet Commerce, and Privacy: The Pervasive Legal Consequences of Modern Geolocation Technologies |first=Kevin F. |last=King |date=8 June 2010}}</ref>
 
===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 <code><body onload="geoFindMe()"></code>:
<sourcesyntaxhighlight lang="javascript">
const geoFindMe = () => {
if (navigator.geolocation) {
Line 52 ⟶ 78:
timeout: 27000
};
</syntaxhighlight>
</source>
 
==See also==
* [[Local search (Internet)]]
* [[Location-based service]]s
*[[Local search (Internet)]]
 
==References==
{{reflistReflist}}
 
==External links==
* [http://www.w3.org/TR/geolocation-API/ W3C Geolocation API Specification]
* [https://whereaminow.co W3C Geolocation API Usage]
 
 
{{W3C standards}}
{{Web interfaces}}
{{Use dmy dates|date=March 2011}}
 
[[Category:Application programming interfaces]]
[[Category:Geolocation]]
[[Category:HTML5]]
[[Category:WebInternet standardsgeolocation]]
[[Category:Location-based software]]
[[Category:GeolocationWeb standards]]