Continuous Location
Continuous Location
Section titled “Continuous Location”Introduction
Section titled “Introduction”watchPosition() continuously monitors the user’s position and calls a callback whenever the position changes.
Watching Position
Section titled “Watching Position”const watchId = navigator.geolocation.watchPosition( (position) => { console.log('Position updated:', position.coords); // Update map, log movement, etc. }, (error) => console.error(error), { enableHighAccuracy: true });Stopping Watch
Section titled “Stopping Watch”// Stop watching position updatesnavigator.geolocation.clearWatch(watchId);console.log('Stopped watching position');Use Cases
Section titled “Use Cases”- Real-time location tracking (maps, delivery tracking)
- Fitness apps (running routes, distance tracking)
- Geofencing (trigger actions when entering/leaving areas)
Summary
Section titled “Summary”watchPosition()— continuous position updates- Returns a watch ID for stopping updates
clearWatch(id)— stop watching- More battery-intensive than one-time requests