I built a small compass project that is able to calculate the devices heading. SO what I got is a function that returns a value between 0° and 360° for the current heading.
What I like to get is a matching value for the current heading direction from an array like this: (["North", "North-East", "East", "South-East", "South", "South-West", "West", "North-West"]
)
(keep in mind: North = 0° / 359°)
However I got no idea how to get a result like this & this few lines below are all that I got so far but it doesn't seems working:
var directions = ["North", "North-East", "East", "South-East", "South", "South-West", "West", "North-West"]
function getDirection(heading) {
var index = Math.round((heading/8)/5,625)
return directions[index]
}
Any help would be very appreciated, thanks in advance.