Rajeev_ranjan Rajeev_ranjan - 3 years ago 260
Javascript Question

Why geolocation is not supporting in my any browser?

Why geolocation is not supporting in my any browser ?
I am new in the world of javascript.

Here is my Code which I am running at node js server.

<!DOCTYPE html>
<html>
<head>
<title>Geolocation</title>
</head>
<body>
<button onclick="getLocation()">Get coords</button>
<h1 id="coords"></h1>
<script>
var x=document.getElementById('coords');
function getLocation(){
if (navigator.Geolocation) {
navigator.Geolocation.getCurrentPosition(showPosition);
}
else{
x.innerHTML="Geolocation is not supported";
}
function showPosition(position){
console.log(position.coords.latitude);
}
}
</script>
</body>
</html>


This is Output

Answer Source

You have to pay attention to the capitalization: Change navigator.Geolocation) to navigator.geolocation.

Documentation of the geolocation API on MDN: https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download