Created
December 12, 2022 03:48
-
-
Save arbo77/a9e88f32c15f8f68de696c2a4c395a56 to your computer and use it in GitHub Desktop.
Convert location format from DMS to DD
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 getDMS2DD(days, minutes, seconds, direction) { | |
direction.toUpperCase(); | |
var dd = days + minutes/60 + seconds/(60*60); | |
//alert(dd); | |
if (direction == "S" || direction == "W") { | |
dd = dd*-1; | |
} // Don't do anything for N or E | |
return dd; | |
} | |
function DMS2DD(dms){ | |
const [d,m,s,dir] = dms.split(" ") | |
return getDMS2DD(parseFloat(d),parseFloat(m),parseFloat(s),dir); | |
} | |
function convertLocation(loc){ | |
const [S,E] = loc.split(",") | |
const [dS,mS,sS,dirS] = S.trim().split(" ") | |
const [dE,mE,sE,dirE] = E.trim().split(" ") | |
return getDMS2DD(parseFloat(dS),parseFloat(mS),parseFloat(sS),dirS) + ", " + getDMS2DD(parseFloat(dE),parseFloat(mE),parseFloat(sE),dirE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment