Geolocation.clearWatch()

Contexto seguro: Esta función está disponible solo en contextos seguros (en-US) (HTTPS), en algunos o todos los navegadores que lo soportan.

El método Geolocation.clearWatch() es usado para remover funciones que monitorizan la ubicación o errores, previamente registradas usando Geolocation.watchPosition()

Sintaxis

js
clearWatch(id)

Parámetros

id

El ID numérico es devuelto cuando se agrega una función para el monitoreo de la ubicación usando el método Geolocation.watchPosition()

Valor devuelto

Ninguno (undefined).

Ejemplos

js
let id;
let target;
let options;

function success(pos) {
  const crd = pos.coords;

  if (target.latitude === crd.latitude && target.longitude === crd.longitude) {
    console.log("Felicidades, has llegado a tu destino.");
    navigator.geolocation.clearWatch(id);
  }
}

function error(err) {
  console.error(`ERROR(${err.code}): ${err.message}`);
}

target = {
  latitude: 0,
  longitude: 0,
};

options = {
  enableHighAccuracy: false,
  timeout: 5000,
  maximumAge: 0,
};

id = navigator.geolocation.watchPosition(success, error, options);

Especificaciones

Specification
Geolocation API
# clearwatch-method

Compatibilidad con navegadores

BCD tables only load in the browser

Véase también