Geolocation Permission Denied
Quick summary
The user blocked location access — your error callback receives PERMISSION_DENIED and no position is returned.
Why this happens
User clicked 'Block' on the geolocation permission prompt
The site is not served over HTTPS (geolocation requires a secure context)
Browser settings disable geolocation globally
Minimal example
navigator.geolocation.getCurrentPosition(
pos => console.log(pos.coords),
err => console.log(err) // err.code === 1, no useful message
);navigator.geolocation.getCurrentPosition(
pos => console.log(pos.coords),
err => {
if (err.code === 1) console.log('Location access denied. Please enable it in settings.');
else console.log('Location error:', err.message);
}
);The default error handler logs a raw error object. Checking err.code === 1 lets you show a helpful message guiding the user to re-enable permission.
How to diagnose
Check error.code === 1 (PERMISSION_DENIED) in the error callback
Verify the page is served over HTTPS or localhost
Check browser site permissions for location
How to fix
Show a friendly message explaining why location is needed and how to re-enable
Fall back to a manual location entry when permission is denied
Only request geolocation on HTTPS after a user gesture
How to prevent
Request geolocation only after a clear user action, not on page load
Always handle the error callback with informative messages