-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathindex.html
1556 lines (1545 loc) · 62.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="color-scheme" content="light dark">
<title>
Geolocation
</title>
<script src="https://www.w3.org/Tools/respec/respec-w3c" async class=
"remove"></script>
<script class="remove">
var respecConfig = {
shortName: "geolocation",
mdn: "geolocation-api",
specStatus: "ED",
editors: [
{
name: "Marcos Cáceres",
company: "Apple Inc.",
companyURL: "https://apple.com",
w3cid: "39125",
},
{
name: "Reilly Grant",
company: "Google",
companyURL: "https://google.com",
w3cid: "83788",
}
],
formerEditors: [
{
name: "Andrei Popescu",
company: "Google Inc.",
companyURL: "https://google.com/",
},
],
group: [ "das", "webapps" ],
previousPublishDate: "2022-02-17",
crEnd: "2022-03-18",
previousMaturity: "CR",
github: "w3c/geolocation",
caniuse: "geolocation",
testSuiteURI: "https://wpt.live/geolocation/",
implementationReportURI: "https://w3c.github.io/geolocation/reports/implementation.html",
xref: "web-platform",
errata: "https://w3c.github.io/geolocation/errata.html",
latestVersion: "https://www.w3.org/TR/geolocation/",
};
</script>
</head>
<body data-cite=
"secure-contexts permissions-policy permissions hr-time html">
<section id="abstract">
<p>
Geolocation provides access to geographical location information
associated with the hosting device.
</p>
</section>
<section id="sotd" class="updateable-rec">
<script class="removeOnSave">
function updateableRecFilter(commit) {
const { message } = commit;
// only show commits that start with Addition: or Correction:
return /^Addition:|^Correction:/.test(message);
}
</script>
<p>
Since this specification become a W3C Recommendation on 01 September
2022, the following substantive additions and/or corrections have been
proposed:
</p><rs-changelog from="REC-2022" filter=
"updateableRecFilter"></rs-changelog>
<p>
A more detailed list of changes can be found in section
[[[#changelog]]]. Reviewers of the document can identify candidate
additions and/or corrections by their distinctive styling in the
document.
</p>
</section>
<section id="introduction" class="informative">
<h2>
Introduction
</h2>
<p>
<cite>Geolocation</cite> defines a high-level interface to location
information associated only with the device hosting the implementation.
Common sources of location information include Global Positioning
System (GPS) and location inferred from network signals such as IP
address, RFID, WiFi and Bluetooth MAC addresses, and GSM/CDMA cell IDs,
as well as user input. The API itself is agnostic of the underlying
location information sources, and no guarantee is given that the API
returns the device's actual location.
</p>
<p>
If an end user [=check permission|grants permission=],
<cite>Geolocation</cite>:
</p>
<ul>
<li>Provides location data as latitude, longitude, altitude, speed, and
heading, as well as the accuracy of the acquired location data, and the
approximate time for when the position was acquired via the
{{GeolocationPosition}} interface.
</li>
<li>Supports "one-shot" position updates via the
{{Geolocation/getCurrentPosition()}} method and the ability to receive
updates for when the position of the hosting device significantly
changes via the {{Geolocation/watchPosition()}} method.
</li>
<li>Using the {{PositionOptions}}'s {{PositionOptions/maximumAge}},
allows an application to request a cached position whose age is no
greater than a specified value (only the last position is cached).
</li>
<li>Provides a way for the application to receive updates about errors,
as a {{GeolocationPositionError}}, that have occurred while [=acquiring
a position=].
</li>
<li>And through {{PositionOptions/enableHighAccuracy}}, supports
requesting "high accuracy" position data, though the request can be
ignored by the user agent.
</li>
</ul>
<section id="scope" class="informative">
<h3>
Scope
</h3>
<p>
This specification is limited to providing a scripting API for
retrieving geographic position information associated with a hosting
device. The geographic position information is provided in terms of
World Geodetic System coordinates [[WGS84]]. It does not include
providing a markup language of any kind, nor does not include
defining a new URL scheme for building URLs that identify geographic
locations.
</p>
</section>
</section>
<section class="informative">
<h2>
Examples
</h2>
<p>
The API is designed to enable both "one-shot" position requests and
repeated position updates. The following examples illustrate common use
cases.
</p>
<section class="informative">
<h3>
Get current position
</h3>
<p>
Request the user's current location. If the user allows it, you will
get back a position object.
</p>
<aside class="example" title="A one-shot position request">
<pre class="js">
navigator.geolocation.getCurrentPosition(position => {
const { latitude, longitude } = position.coords;
// Show a map centered at latitude / longitude.
});
</pre>
</aside>
</section>
<section class="informative">
<h3>
Watch a position
</h3>
<p>
Request the ability to watch user's current location. If the user
allows it, you will get back continuous updates of the user's
position.
</p>
<aside class="example" title=
"Watching a position for repeated updates">
<pre class="js">
const watchId = navigator.geolocation.watchPosition(position => {
const { latitude, longitude } = position.coords;
// Show a map centered at latitude / longitude.
});
</pre>
</aside>
</section>
<section class="informative">
<h3>
Stop watching a position
</h3>
<p>
Stop watching for position changes by calling the
{{Geolocation/clearWatch()}} method.
</p>
<aside class="example" title="Using clearWatch()">
<pre class="js">
const watchId = navigator.geolocation.watchPosition(
position => console.log(position);
);
function buttonClickHandler() {
// Cancel the updates when the user clicks a button.
navigator.geolocation.clearWatch(watchId);
}
</pre>
<p>
And a HTML `button` that when pressed stops watching the position.
</p>
<pre class="html">
<button onclick="buttonClickHandler()">
Stop watching location
</button>
</pre>
</aside>
</section>
<section class="informative">
<h3>
Handling errors
</h3>
<p>
When an error occur, the second argument of the
{{Geolocation/watchPosition()}} or
{{Geolocation/getCurrentPosition()}} method gets called with a
{{GeolocationPositionError}} error, which can help you figure out
what might have gone wrong.
</p>
<aside class="example" title="Handling errors">
<pre class="js">
// Request repeated updates.
const watchId = navigator.geolocation.watchPosition(
scrollMap, handleError
);
function scrollMap(position) {
const { latitude, longitude } = position.coords;
// Scroll map to latitude / longitude.
}
function handleError(error) {
// Display error based on the error code.
const { code } = error;
switch (code) {
case GeolocationPositionError.TIMEOUT:
// Handle timeout.
break;
case GeolocationPositionError.PERMISSION_DENIED:
// User denied the request.
break;
case GeolocationPositionError.POSITION_UNAVAILABLE:
// Position not available.
break;
}
}
</pre>
</aside>
</section>
<section class="informative">
<h3>
Using `maximumAge` as cache control
</h3>
<p>
By default, the API always attempts to return a cached position so
long as it has a previously acquired position. In this example, we
accept a position whose age is no greater than 10 minutes. If the
user agent does not have a fresh enough cached position object, it
automatically acquires a new position.
</p>
<aside class="example" title="Getting cached position">
<pre class="js">
navigator.geolocation.getCurrentPosition(
successCallback,
console.error,
{ maximumAge: 600_000 }
);
function successCallback(position) {
// By using the 'maximumAge' member above, the position
// object is guaranteed to be at most 10 minutes old.
}
</pre>
</aside>
</section>
<section class="informative">
<h2>
Using `timeout`
</h2>
<p>
If you require location information in a time sensitive manner, you
can use the {{PositionOptions}} {{PositionOptions/timeout}} member to
limit the amount of time you are willing to wait to [=acquire a
position=].
</p>
<aside class="example" title="Timing out a position request">
<pre class="js">
// Request a position. We are only willing to wait 10
// seconds for it.
navigator.geolocation.getCurrentPosition(
successCallback,
errorCallback,
{ timeout: 10_000 }
);
function successCallback(position) {
// Request finished in under 10 seconds...
}
function errorCallback(error) {
switch (error.code) {
case GeolocationPositionError.TIMEOUT:
// We didn't get it in a timely fashion.
doFallback();
// Acquire a new position object,
// as long as it takes.
navigator.geolocation.getCurrentPosition(
successCallback, errorCallback
);
break;
case "...": // treat the other error cases.
}
}
function doFallback() {}
</pre>
</aside>
</section>
<section class="informative">
<h3>
Enabling the API in third-party contexts
</h3>
<p>
The [=policy-controlled feature/default allowlist=] of `'self'`
allows API usage in same-origin nested frames but prevents
third-party content from using the API.
</p>
<p>
Third-party usage can be selectively enabled by adding the
[^iframe/allow^]`="geolocation"` attribute to an [^iframe^] element:
</p>
<aside class="example" title="Enabling Geolocation in an iframe">
<pre class="html">
<iframe
src="https://third-party.com"
allow="geolocation">
</iframe>
</pre>
</aside>
<p>
Alternatively, the API can be disabled in a first-party context by
specifying an HTTP response header:
</p>
<aside class="example" title="Permissions Policy over HTTP">
<pre class="http">
Permissions-Policy: geolocation=()
</pre>
</aside>
<p>
See [[[permissions-policy]]] for more details about the
`Permissions-Policy` HTTP header.
</p>
</section>
</section>
<section id="privacy" class="informative">
<h2>
Privacy considerations
</h2>
<p>
The API defined in this specification is used to retrieve the
geographic location of a hosting device. In almost all cases, this
information also discloses the location of the user of the device,
thereby potentially compromising the user's privacy.
</p>
<section class="informative">
<h3>
User consent
</h3>
<p>
<cite>Geolocation</cite> is a [=powerful feature=] that requires
[=express permission=] from an end-user before any location data is
shared with a web application. This requirement is normatively
enforced by the [=check permission=] steps on which the
{{Geolocation/getCurrentPosition()}} and
{{Geolocation/watchPosition()}} methods rely.
</p>
<p>
An end-user will generally give [=express permission=] through a user
interface, which usually present a range of permission
[=permission/lifetimes=] that the end-user can choose from. The
choice of [=permission/lifetimes=] vary across user agents, but they
are typically time-based (e.g., "a day"), or until browser is closed,
or the user might even be given the choice for the permission to be
granted indefinitely. The permission [=permission/lifetimes=] dictate
how long a user agent [=permission/grants=] a permission before that
permission is automatically reverted back to its default [=permission
state=], prompting the end-user to make a new choice upon subsequent
use.
</p>
<p>
Although the granularity of the permission [=permission/lifetime=]
varies across user-agents, this specification urges user agents to
limit the lifetime to a single browsing session by default (see
[[[#check-permission]]] for normative requirements).
</p>
</section>
<section id="privacy_for_recipients" class="informative">
<h3>
Privacy considerations for recipients of location information
</h3>
<p class="note" title=
"Developers' responsibility with this sensitive data">
This section applies to "recipients", which generally means
developers utilizing <cite>Geolocation</cite>. Although it's
impossible for the user agent, or this specification, to enforce
these requirements, developers need to read this section carefully
and do their best to adhere to the suggestions below. Developers need
to be aware that there might be privacy laws in their jurisdictions
that can govern the usage and access to users' location data.
</p>
<p>
Recipients ought to only request position information when necessary,
and only use the location information for the task for which it was
provided to them. Recipients ought to dispose of location information
once that task is completed, unless expressly permitted to retain it
by the user. Recipients need to also take measures to protect this
information against unauthorized access. If location information is
stored, users need to be allowed to update and delete this
information.
</p>
<p>
The recipients of location information need to refrain from
retransmitting the location information without the user’s express
permission. Care needs to be taken when retransmitting and the use of
encryption is encouraged.
</p>
<p>
Recipients ought to clearly and conspicuously disclose the fact that
they are collecting location data, the purpose for the collection,
how long the data is retained, how the data is secured, how the data
is shared if it is shared, how users can access, update and delete
the data, and any other choices that users have with respect to the
data. This disclosure needs to include an explanation of any
exceptions to the guidelines listed above.
</p>
</section>
<section id="implementation_considerations" class="informative">
<h3>
Implementation considerations
</h3>
<p>
Implementers are advised to consider the following aspects that can
negatively affect the privacy of their users: in certain cases, users
can inadvertently grant permission to the user agent to disclose
their location to websites. In other cases, the content hosted at a
certain URL changes in such a way that the previously granted
location permissions no longer apply as far as the user is concerned.
Or the users might simply change their minds.
</p>
<p>
Predicting or preventing these situations is inherently difficult.
Mitigation and in-depth defensive measures are an implementation
responsibility and not prescribed by this specification. However, in
designing these measures, implementers are advised to enable user
awareness of location sharing, and to provide access to user
interfaces that enable revocation of permissions.
</p>
</section>
<section id="check-permission">
<h2>
Checking permission to use the API
</h2>
<p>
<cite>Geolocation</cite> is a [=default powerful feature=] identified
by the [=powerful feature/name=] <code><dfn class=
"permission">"geolocation"</dfn></code>.
</p>
<p>
When <dfn data-local-lt="check permission">checking permission</dfn>
to use the API, a user agent MAY suggest time-based [=permission=]
[=permission/lifetimes=], such as "24 hours", "1 week", or choose to
remember the permission [=permission/grant=] indefinitely. However,
it is RECOMMENDED that a user agent prioritize restricting the
[=permission=] [=permission/lifetime=] to a single session: This can
be, for example, until the [=environment settings object/realm=] is
destroyed, the end-user [=navigates=] away from the [=origin=], or
the relevant browser tab is closed.
</p>
</section>
</section>
<section id="security">
<h2>
Security considerations
</h2>
<p>
There are no security considerations associated with Geolocation at the
time of publication. However, readers are advised to read the
[[[#privacy]]].
</p>
</section>
<section id="navigator_interface" data-dfn-for="Navigator">
<h2>
Extensions to the `Navigator` interface
</h2>
<pre class="idl">
partial interface Navigator {
[SameObject] readonly attribute Geolocation geolocation;
};
</pre>
</section>
<section id="geolocation_interface" data-dfn-for="Geolocation">
<h2>
`Geolocation` interface and callbacks
</h2>
<pre class="idl">
[Exposed=Window]
interface Geolocation {
undefined getCurrentPosition (
PositionCallback successCallback,
optional PositionErrorCallback? errorCallback = null,
optional PositionOptions options = {}
);
long watchPosition (
PositionCallback successCallback,
optional PositionErrorCallback? errorCallback = null,
optional PositionOptions options = {}
);
undefined clearWatch (long watchId);
};
callback PositionCallback = undefined (
GeolocationPosition position
);
callback PositionErrorCallback = undefined (
GeolocationPositionError positionError
);
</pre>
<section>
<h2>
Internal slots
</h2>
<p>
Instances of {{Geolocation}} are created with the internal slots in
the following table:
</p>
<table class="data">
<tr>
<th>
Internal slot
</th>
<th>
Description
</th>
</tr>
<tr>
<td>
<dfn data-dfn-for="Geolocation">[[\cachedPosition]]</dfn>
</td>
<td>
A {{GeolocationPosition}}, initialized to null. It's a reference
to the last acquired position and serves as a cache. A user agent
MAY evict {{Geolocation/[[cachedPosition]]}} by resetting it to
null at any time for any reason.
</td>
</tr>
<tr>
<td>
<dfn data-dfn-for="Geolocation">[[\watchIDs]]</dfn>
</td>
<td>
Initialized as an empty [=list=] of {{unsigned long}}
[=list/item|items=].
</td>
</tr>
</table>
</section>
<section>
<h2>
`getCurrentPosition()` method
</h2>
<p data-tests=
"getCurrentPosition_IDL.https.html, getCurrentPosition_TypeError.html">
The <dfn>getCurrentPosition</dfn>(|successCallback:PositionCallback|,
|errorCallback:PositionErrorCallback?|, |options:PositionOptions|)
method steps are:
</p>
<ol class="algorithm">
<li>
<aside class="correction" id="c1">
<span class="marker">Candidate Correction:</span> Updated
reference to the global object to use [=this=] for consistency in
error handling within geolocation retrieval.
</aside><del cite="#c1">If the [=current settings object=]'s
[=relevant global object=]'s [=associated `Document`=] is not
[=Document/fully active=]:</del> <ins cite="#c1">If [=this=]'s
[=relevant global object=]'s [=associated `Document`=] is not
[=Document/fully active=]:</ins>
<ol>
<li>[=Call back with error=] |errorCallback| and
{{GeolocationPositionError/POSITION_UNAVAILABLE}}.
</li>
<li>Terminate this algorithm.
</li>
</ol>
</li>
<li>[=Request a position=] passing [=this=], |successCallback|,
|errorCallback|, and |options|.
</li>
</ol>
</section>
<section>
<h2>
`watchPosition()` method
</h2>
<p data-tests=
"getCurrentPosition_permission_allow.https.html, getCurrentPosition_permission_deny.https.html">
The <dfn>watchPosition</dfn>(|successCallback:PositionCallback|,
|errorCallback:PositionErrorCallback?|, |options:PositionOptions|)
method steps are:
</p>
<ol class="algorithm">
<li>
<aside class="correction" id="c2">
<span class="marker">Candidate Correction:</span> Simplified
reference to the global object in the method steps for checking
document's activity status.
</aside><del cite="#c2">If the [=current settings object=]'s
[=relevant global object=]'s [=associated `Document`=] is not
[=Document/fully active=]:</del> <ins cite="#c2">If [=this=]'s
[=relevant global object=]'s [=associated `Document`=] is not
[=Document/fully active=]:</ins>
<ol>
<li>[=Call back with error=] passing |errorCallback| and
{{GeolocationPositionError/POSITION_UNAVAILABLE}}.
</li>
<li>Return 0.
</li>
</ol>
</li>
<li>Let |watchId:unsigned long| be an [=implementation-defined=]
{{unsigned long}} that is greater than zero.
</li>
<li>[=List/Append=] |watchId| to [=this=]'s
{{Geolocation/[[watchIDs]]}}.
</li>
<li>[=Request a position=] passing [=this=], |successCallback|,
|errorCallback|, |options|, and |watchId|.
</li>
<li>Return |watchId|.
</li>
</ol>
</section>
<section>
<h2>
`clearWatch()` method
</h2>
<p data-tests="clearWatch_TypeError.html">
When <dfn>clearWatch()</dfn> is invoked, the user agent MUST:
</p>
<ol class="algorithm">
<li>[=List/Remove=] |watchId| from [=this=]'s
{{Geolocation/[[watchIDs]]}}.
</li>
</ol>
</section>
<section>
<h2>
Request a position
</h2>
<p>
To <dfn>request a position</dfn>, pass a {{Geolocation}}
|geolocation:Geolocation|, a {{PositionCallback}}
|successCallback:PositionCallback|, a {{PositionErrorCallback?}}
|errorCallback:PositionErrorCallback?|, a {{PositionOptions}}
|options:PositionOptions|, and an optional |watchId:unsigned long|:
</p>
<ol class="algorithm">
<li>Let |watchIDs:List| be |geolocation|'s
{{Geolocation/[[watchIDs]]}}.
</li>
<li>Let |document:Document| be the |geolocation|'s [=relevant global
object=]'s [=associated `Document`=].
</li>
<li data-tests="">If |document| is not [=allowed to use=] the
"geolocation" feature:
<ol>
<li>If |watchId| was passed, [=List/remove=] |watchId| from
|watchIDs|.
</li>
<li>[=Call back with error=] passing |errorCallback| and
{{GeolocationPositionError/PERMISSION_DENIED}}.
</li>
<li>Terminate this algorithm.
</li>
</ol>
</li>
<li>
<aside class="correction" id="c7">
<span class="marker">Candidate Correction:</span> Added missing
step to handle [=non-secure contexts=].
</aside><ins cite="#c7">If |geolocation|'s [=environment settings
object=] is a [=non-secure context=]:
<ol>
<li>If |watchId| was passed, [=List/remove=] |watchId| from
|watchIDs|.
</li>
<li>[=Call back with error=] passing |errorCallback| and
{{GeolocationPositionError/PERMISSION_DENIED}}.
</li>
<li>Terminate this algorithm.
</li>
</ol></ins>
</li>
<li>If |document:Document|'s [=Document/visibility state=] is
"hidden", wait for the following [=page visibility change steps=] to
run:
<ol>
<li>Assert: |document|'s [=Document/visibility state=] is
"visible".
</li>
<li>Continue to the next steps below.
</li>
</ol>
</li>
<li>Let |descriptor| be a new {{PermissionDescriptor}} whose
{{PermissionDescriptor/name}} is <a>"geolocation"</a>.
</li>
<li>[=In parallel=]:
<ol>
<li>Set |permission| to [=request permission to use=]
|descriptor|.
</li>
<li data-tests=
"getCurrentPosition_permission_allow.https.html, getCurrentPosition_permission_deny.https.html">
If |permission| is "denied", then:
<ol>
<li>If |watchId| was passed, [=list/remove=] |watchId| from
|watchIDs|.
</li>
<li>[=Call back with error=] passing |errorCallback| and
{{GeolocationPositionError/PERMISSION_DENIED}}.
</li>
<li>Terminate this algorithm.
</li>
</ol>
</li>
<li>Wait to [=acquire a position=] passing |successCallback|,
|errorCallback|, |options|, and |watchId|.
</li>
<li>If |watchId| was not passed, terminate this algorithm.
</li>
<li>While |watchIDs| [=list/contains=] |watchId|:
<ol>
<li>
<span id="wait-for-change">Wait for a significant change of
geographic position</span>. What constitutes a significant
change of geographic position is left to the
implementation. User agents MAY impose a rate limit on how
frequently position changes are reported.
</li>
<li>If |document| is not [=Document/fully active=] or
[=Document/visibility state=] is not "visible", go back to
the previous step and again <a href="#wait-for-change">wait
for a significant change of geographic position</a>.
<aside class="note" title=
"Position updates are exclusively for fully-active visible documents">
<p>
The desired effect here being that position updates are
exclusively delivered to fully active documents that
are visible; Otherwise the updates get silently
"dropped on the floor". Only once a document again
becomes fully active and visible (e.g., an [^iframe^]
gets reattached to a parent document), do the position
updates once again start getting delivered.
</p>
</aside>
</li>
<li>Wait to [=acquire a position=] passing |successCallback|,
|errorCallback|, |options|, and |watchId|.
</li>
</ol>
</li>
</ol>
</li>
</ol>
</section>
<section>
<h2>
Acquire a position
</h2>
<p>
To <dfn data-local-lt=
"acquiring a position|acquire a position">acquire a position</dfn>,
passing {{PositionCallback}} |successCallback:PositionCallback|, a
{{PositionErrorCallback?}} |errorCallback:PositionErrorCallback?|,
{{PositionOptions}} |options:PositionOptions|, and an optional
|watchId:unsigned long|.
</p>
<ol class="algorithm">
<li>If |watchId| was passed and [=this=]'s
{{Geolocation/[[watchIDs]]}} does not [=list/contain=] |watchId|,
terminate this algorithm.
</li>
<li>Let |acquisitionTime:EpochTimeStamp| be a new {{EpochTimeStamp}}
that represents now.
</li>
<li>Let |timeoutTime| be the sum of |acquisitionTime| and
|options|.{{PositionOptions/timeout}}.
</li>
<li>Let |cachedPosition:GeolocationPosition| be [=this=]'s
{{Geolocation/[[cachedPosition]]}}.
</li>
<li>Create an implementation-specific |timeout| task that elapses at
|timeoutTime|, during which it tries to acquire the device's position
by running the following steps:
<ol>
<li>Let |permission| be [=get the current permission state=] of
<a>"geolocation"</a>.
</li>
<li>If |permission| is "denied":
<ol>
<li>Stop |timeout|.
</li>
<li>Do the <a href="#permission-denied">user or system denied
permission</a> failure case step.
</li>
</ol>
</li>
<li>If |permission| is "granted":
<ol>
<li>Let |position| be null.
</li>
<li>If |cachedPosition| is not null, and
|options|.{{PositionOptions/maximumAge}} is greater than 0:
<ol>
<li>Let |cacheTime:long| be |acquisitionTime| minus the
value of the |options|.{{PositionOptions/maximumAge}}
member.
</li>
<li>
<aside class="correction" id="c8">
<span class="marker">Candidate Correction:</span>
Updated to ensure that the algorithm terminates
immediately if a valid cached position is used,
avoiding unnecessary steps.
</aside>If |cachedPosition|'s
{{GeolocationPosition/timestamp}}'s value is greater
than |cacheTime|, and
|cachedPosition|.{{GeolocationPosition/[[isHighAccuracy]]}}
equals
|options|.{{PositionOptions/enableHighAccuracy}}<del cite="#c8">,
set |position| to |cachedPosition|.</del> <ins cite=
"#c8">:
<ol>
<li>[=Queue a task=] on the [=geolocation task
source=] with a step that [=invokes=]
|successCallback| with « |cachedPosition| » and "`report`".
</li>
<li>Terminate this algorithm.
</li>
</ol></ins>
</li>
</ol>
</li>
<li>Otherwise, if |position| is not |cachedPosition|, try to
acquire position data from the underlying system, optionally
taking into consideration the value of
|options|.{{PositionOptions/enableHighAccuracy}} during
acquisition.
</li>
<li>If the |timeout| elapses during acquisition, or acquiring
the device's position results in failure:
<ol>
<li>Stop the |timeout|.
</li>
<li>Go to <a href="#errors-reasons">dealing with
failures</a>.
</li>
<li>Terminate this algorithm.
</li>
</ol>
</li>
<li data-cite="infra">If acquiring the position data from the
system succeeds:
<aside class="correction" id="c9">
<span class="marker">Candidate Correction:</span> We now
use a [=map=] to represent the position data. Clarified
the units and reference systems for latitude, longitude,
and altitude, ensuring consistency with the updated
attribute definitions. Updated the descriptions of the
speed and heading to specify measurement units and
conditions for null values, aligning with the overall
enhancements to attribute accuracy and clarity.
</aside><ins cite="#c9">
<ol data-cite="infra">
<li>Let |positionData| be a [=map=] with the following
name/value pairs based on the acquired position data:
<dl>
<dt>
"longitude"
</dt>
<dd>
A {{double}} that represents the longitude
coordinates on the Earth's surface in degrees,
using the [[WGS84]] coordinate system. Longitude
measures how far east or west a point is from the
Prime Meridian.
</dd>
<dt>
"altitude"
</dt>
<dd>
A {{double?}} that represents the altitude in
meters above the [[WGS84]] ellipsoid, or `null` if
not available. Altitude measures the height above
sea level.
</dd>
<dt>
"accuracy"
</dt>
<dd>
A non-negative {{double}} that represents the
accuracy value indicating the 95% confidence level
in meters. Accuracy measures how close the measured
coordinates are to the true position.
</dd>
<dt>
"altitudeAccuracy"
</dt>
<dd>
A non-negative {{double?}} that represents the
altitude accuracy, or `null` if not available,
indicating the 95% confidence level in meters.
Altitude accuracy measures how close the measured
altitude is to the true altitude.
</dd>
<dt>
"speed"
</dt>
<dd>
A non-negative {{double?}} that represents the
speed in meters per second, or `null` if not
available. Speed measures how fast the device is
moving.
</dd>
<dt>
"heading"
</dt>
<dd>
A {{double?}} that represents the heading in
degrees, or `null` if not available or the device
is stationary. Heading measures the direction in
which the device is moving relative to true north.
</dd>
</dl>
</li>
<li>Set |position| to [=a new `GeolocationPosition`=]
passing |positionData|, |acquisitionTime| and
|options|.{{PositionOptions/enableHighAccuracy}}.
</li>
<li>Set [=this=]'s {{Geolocation/[[cachedPosition]]}} to
|position|.
</li>
</ol></ins> <del cite="#c9">
<ol>
<li>Set |position| to [=a new `GeolocationPosition`=]
passing |acquisitionTime| and
|options|.{{PositionOptions/enableHighAccuracy}}.
</li>
<li>Set [=this=]'s {{Geolocation/[[cachedPosition]]}} to
|position|.
</li>
</ol></del>
</li>
<li>Stop the |timeout|.
</li>
<li>[=Queue a task=] on the [=geolocation task source=] with
a step that [=invokes=] |successCallback| with « |position| »
and "`report`".
</li>
</ol>
</li>
</ol>
<dl class="switch">
<dt id="errors-reasons">
Dealing with failures:
</dt>
<dd>
<ul>
<li>If acquiring a position fails, do one of the following
based on the condition that matches the failure:
<dl class="switch">
<dt id="permission-denied">
User or system denied permission:
</dt>
<dd>
<p>
[=Call back with error=] passing |errorCallback| and
{{GeolocationPositionError/PERMISSION_DENIED}}.
</p>
<aside class="note" title=
"Browser permission VS OS permission">
<p>
On certain platforms, there can be a circumstance
where the user has [=permission/granted=] the user