Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get gps location using javascript

I am using tablet, working on html application, want to get gps location without using any network connection. please suggest me simple ways.

like image 937
Teerath Kumar Avatar asked Oct 15 '25 09:10

Teerath Kumar


1 Answers

Using JS you can get it like this

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;
}

$(document).ready(function(){
  getLocation();
});
#demo{
background-color: tomato;
width:200px;
height:50px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<div id="demo"></div>
like image 120
Panther Avatar answered Oct 16 '25 22:10

Panther



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!