Answers for "javascript get current latitude longitude"

0

html geolocation

//Click the button to get your coordinates
<button onclick="getLocation()">Try It</button>
<script>
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;
}
</script>
Posted by: Guest on January-24-2021
0

validate latitude longitude javascript

function validateLatLng(lat, lng) {    
  let pattern = new RegExp('^-?([1-8]?[1-9]|[1-9]0)\\.{1}\\d{1,6}');
  
  return pattern.test(lat) && pattern.test(lng);
}
Posted by: Guest on April-10-2020

Code answers related to "javascript get current latitude longitude"

Browse Popular Code Answers by Language