From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../api/geolocation/getcurrentposition/index.html | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 files/fr/web/api/geolocation/getcurrentposition/index.html (limited to 'files/fr/web/api/geolocation/getcurrentposition') diff --git a/files/fr/web/api/geolocation/getcurrentposition/index.html b/files/fr/web/api/geolocation/getcurrentposition/index.html new file mode 100644 index 0000000000..25c0c9d97c --- /dev/null +++ b/files/fr/web/api/geolocation/getcurrentposition/index.html @@ -0,0 +1,90 @@ +--- +title: Geolocation.getCurrentPosition() +slug: Web/API/Geolocation/getCurrentPosition +tags: + - API + - Geolocation + - Méthode + - Reference +translation_of: Web/API/Geolocation/getCurrentPosition +--- +
{{securecontext_header}}{{APIRef("Geolocation API")}}
+ +

La méthode Geolocation.getCurrentPosition() fournit la position actuelle de l'appareil.

+ +

Syntaxe

+ +
navigator.geolocation.getCurrentPosition(success[, error[, [options]])
+ +

Paramètres

+ +
+
success
+
Une fonction de rappel qui prend un objet {{domxref("Position")}} comme argument.
+
error {{optional_inline}}
+
Une fonction de rappel qui prend un objet {{domxref("PositionError")}} comme argument.
+
options {{optional_inline}}
+
Un objet {{domxref("PositionOptions")}} optionnel. Les options décrites par cet objet sont : +
    +
  • maximumAge : un entier qui exprime une durée en millisecondes ou l'infini pour indiquer la durée maximale pendant laquelle mettre en cache la position.
  • +
  • timeout : un entier qui exprime la durée, en millisecondes, avant que la fonction de rappel error soit appelé. Si cette propriété vaut 0, la fonction d'erreur ne sera jamais appelée.
  • +
  • enableHighAccuracy : un booléen qui indique si une précision élevée est requise.
  • +
+
+
+ +

Exemples

+ +
var options = {
+  enableHighAccuracy: true,
+  timeout: 5000,
+  maximumAge: 0
+};
+
+function success(pos) {
+  var crd = pos.coords;
+
+  console.log('Votre position actuelle est :');
+  console.log(`Latitude : ${crd.latitude}`);
+  console.log(`Longitude : ${crd.longitude}`);
+  console.log(`La précision est de ${crd.accuracy} mètres.`);
+}
+
+function error(err) {
+  console.warn(`ERREUR (${err.code}): ${err.message}`);
+}
+
+navigator.geolocation.getCurrentPosition(success, error, options);
+
+ +

Spécifications

+ + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('Geolocation')}}{{Spec2('Geolocation')}}Spécification initiale.
+ +

Compatibilité des navigateurs

+ + + +

{{Compat("api.Geolocation.getCurrentPosition")}}

+ +

Voir aussi

+ + -- cgit v1.2.3-54-g00ecf