Answers for "get location from latitude and longitude javascript"

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

javascript converting latitude longitude to gps coordinates

#Convert lat/long to gps coordinates
function ConvertDEGToDMS(deg, lat) {
    var absolute = Math.abs(deg);

    var degrees = Math.floor(absolute);
    var minutesNotTruncated = (absolute - degrees) * 60;
    var minutes = Math.floor(minutesNotTruncated);
    var seconds = ((minutesNotTruncated - minutes) * 60).toFixed(2);

    if (lat) {
        var direction = deg >= 0 ? "N" : "S";
    } else {
        var direction = deg >= 0 ? "E" : "W";
    }

    return degrees + "°" + minutes + "'" + seconds + "\"" + direction;
}
Posted by: Guest on November-24-2020

Code answers related to "get location from latitude and longitude javascript"

Browse Popular Code Answers by Language