Last active
September 9, 2023 19:52
-
-
Save Arifursdev/0f48c79a6364bd8364e690ea8a9454bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toDMS(deg) { | |
var d = Math.floor(deg); | |
var min = Math.floor((deg - d) * 60); | |
var sec = ((deg - d - min / 60) * 3600).toFixed(2); | |
return d + "° " + min + "' " + sec + "\""; | |
} | |
function convertLatLngToDMS(lat, lng) { | |
var latDMS = lat >= 0 ? "N" : "S"; | |
var lngDMS = lng >= 0 ? "E" : "W"; | |
lat = Math.abs(lat); | |
lng = Math.abs(lng); | |
var latDMSString = toDMS(lat); | |
var lngDMSString = toDMS(lng); | |
return latDMSString + " " + latDMS + " " + lngDMSString + " " + lngDMS; | |
} | |
const lat = 64.75960; | |
const lng = -104.21007; | |
const dms = convertLatLngToDMS(lat, lng) | |
console.log(dms); // 64° 45' 34.56" N 104° 12' 36.25" W |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment