The Geolocation API provides the user's location with their permission.
navigator.geolocation.getCurrentPosition(
(position) => {
console.log(position.coords.latitude);
console.log(position.coords.longitude);
},
(error) => {
console.error(error.message);
}
);
Always handle the error case since users may deny permission.