Avoid using high accuracy geolocation in web applications (@ecocode/avoid-high-accuracy-geolocation
)
recommended
config.
High-precision geolocation typically requires more power from the device's GPS hardware. By requesting less accurate geolocation, you can reduce the power consumption, leading to extended battery life, which is crucial for mobile devices.
Obtaining highly accurate geolocation often involves more complex calculations and processing, which can increase CPU usage. If the application or service does not critically require pinpoint accuracy, opting for a less accurate geolocation can help minimize the strain on the device's CPU.
var options = { enableHighAccuracy: true, timeout: 5000, maximumAge: 0 }; // Non-compliant
navigator.geolocation.getCurrentPosition(
(pos) => console.log(pos),
(err) => console.warn(err),
options
);
In these examples, the enableHighAccuracy option is set to false (the default), indicating that the application prefers lower-accuracy geolocation to conserve resources:
navigator.geolocation.getCurrentPosition((pos) => console.log(pos)); // Compliant by default
var options = { enableHighAccuracy: false, timeout: 5000, maximumAge: 0 }; // Compliant
navigator.geolocation.getCurrentPosition(
(pos) => console.log(pos),
(err) => console.warn(err),
options
);
- Mozilla Web Technology for Developers - getCurrentPosition() method