15. prompts the user to allow or decline their geographical location
Fri Aug 26 2022 14:23:35 GMT+0000 (Coordinated Universal Time)
Saved by
@mwebrania
#javascript
let geoloc = document.getElementById("theElementID");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
geoloc.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
geoloc.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
content_copyCOPY
Comments