In this article, I will share with you how to get the current location in javascript with the example. get current let-long in javascript is very easy and you get done this help of the getCurrentPosition() in javascript.
JavaScript has a huge By default functions and it can be very helpful in our web application. so, you can get the current location in the javascript help of a few line codes.
here is an example.
<!DOCTYPE html>
<html>
<head>
<title>Get User Location</title>
</head>
<body>
<p>Click the button to get your live location.</p>
<button onclick="getLocation()">Get Location</button>
<p id="demo"></p>
<script type="text/javascript">
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) {
console.log(position);
x.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude;
}
</script>
</body>
</html>
i hope you like this article.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
How to create custom 404 page in laravel
In this tutorials, i am showing to how t...Restful API In Laravel 5.5 Using jwt Authentication
Today, we are share with you how to buil...How to toggle text inside and element on click using jQuery
Use the jQuery text() method You can...Firebase Phone Authentication With Invisible reCaptcha in Laravel5.6
Today, we are share with you how to impl...Start Applications Automatically on Login in Ubuntu
Many of us need to open certain applicat...