Welcome aboard! We are happy you are here and wish you good net-raft!
<!DOCTYPE html>
<html>
<body>
<button onclick="getLocation()">Get</button>
<script>
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
document.write ("Geolocation is not supported by this browser.");
}
}
function showPosition(position) {
document.write ("Latitude: " + position.coords.latitude + ", Longitude: " + position.coords.longitude);
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<script>
function YourPosition(myposition)
{
var lat1 = myposition.coords.latitude;
var lng1 = myposition.coords.longitude;
document.write (lat1 + " , " + lng1)
}
if(navigator.geolocation)
navigator.geolocation.getCurrentPosition(YourPosition);
else
alert("something was wrong");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<button onclick="getmyLocation()">click</button>
<p id="test"></p>
<script>
var x = document.getElementById("test");
function getmyLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showing_position, showing_error);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showing_position(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
function showing_error(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
x.innerHTML = "User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML = "Location information is unavailable."
break;
case error.TIMEOUT:
x.innerHTML = "The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML = "An unknown error occurred."
break;
}
}
</script>
</body>
</html>
The most helpful JAVASCRIPT solutions
How can I get the last day and the next day in javascript ?JAVASCRIPT Click to see more ... 5.8K 507