'How to render a message in H1 element using geolocation function in javascript
In this code I would like to show a message in the h1 element in case the browser doesn't support geolocation or the user doesn't allow to check its current location. After this part of code it continues, and if geolocation is enabled, I fetch the information and render it.
function getLocation() {
if (!navigator.geolocation) {
const errorGettingGeolocation = "Geolocation is not supported by this browser or was not allowed by user.";
const cityHtml = document.getElementById("cityName");
cityHtml.innerText = errorGettingGeolocation;
return;
} else if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
}
}
How can i render this message and then continue running the code? EDIT: When I console.log inside function getLocation, I get return, but if I console.log inside if (!navigator.geolocation), I don't get any return. It never check this if condition.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
