How to Get Current Location in JavaScript Example


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>
	<title>Get User Location</title>
	<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) {
		    } else {
		        x.innerHTML = "Geolocation is not supported by this browser.";

		function showPosition(position) {
		    x.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude;

i hope you like this article.