Created
March 1, 2017 06:16
-
-
Save abidvf/cb0537328953bbc288c9be3785a7895d 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 getDirection(magneticHeading) { | |
var textDirection; | |
if (typeof magneticHeading !== "number") { | |
textDirection = ''; | |
} else if (magneticHeading >= 337.5 || (magneticHeading >= 0 && magneticHeading <= 22.5)) { | |
textDirection = 'N'; | |
} else if (magneticHeading >= 22.5 && magneticHeading <= 67.5) { | |
textDirection = 'NE'; | |
} else if (magneticHeading >= 67.5 && magneticHeading <= 112.5) { | |
textDirection = 'E'; | |
} else if (magneticHeading >= 112.5 && magneticHeading <= 157.5) { | |
textDirection = 'SE'; | |
} else if (magneticHeading >= 157.5 && magneticHeading <= 202.5) { | |
textDirection = 'S'; | |
} else if (magneticHeading >= 202.5 && magneticHeading <= 247.5) { | |
textDirection = 'SW'; | |
} else if (magneticHeading >= 247.5 && magneticHeading <= 292.5) { | |
textDirection = 'W'; | |
} else if (magneticHeading >= 292.5 && magneticHeading <= 337.5) { | |
textDirection = 'NW'; | |
} else { | |
textDirection = textDirection; | |
} | |
return textDirection; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment