I am writing an web application that requires the current geolocation of user. For identifying geolocation I have used the following code that uses HTML5 geolocation api. I have taken this code from W3schools.
<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to get your coordinates:</p>
<button onclick="getLocation()">Try It</button>
<script>
var x=document.getElementById("demo");
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else{x.innerHTML="Geolocation is not supported by this browser.";}
}
function showPosition(position)
{
x.innerHTML="Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
</script>
</body>
</html>
I have run this code with Tomcat, but it is not working neither in Firefox nor in Chrome. Then I have tried this code with "Try It Yourself" in W3Schools and it is not working even there also neither in Firefox nor in Chrome. I am behind the proxy.
I have introduced an alert() statement at the start of body of the function showPosition() and it did not get called. So it seems this function is not getting called at all. I have no clue how to fix that. I desperately need to fix that. I have previously posted that problem but got no response probably because of not framing the problem clearly. So I am again posting the problem.
Is there any other way to get the geolocation of the users who are accessing this application throuogh computers. So please help. Thank you.
EDIT: I have hosted this file on Tomcat. Each time I am executing, it is giving error code 3 i.e. timeout. But I have executed the same Javascript two months back. Then it executed perfectly. Is it a problem with current version of my browser?