1#Convert lat/long to gps coordinates
2function ConvertDEGToDMS(deg, lat) {
3 var absolute = Math.abs(deg);
4
5 var degrees = Math.floor(absolute);
6 var minutesNotTruncated = (absolute - degrees) * 60;
7 var minutes = Math.floor(minutesNotTruncated);
8 var seconds = ((minutesNotTruncated - minutes) * 60).toFixed(2);
9
10 if (lat) {
11 var direction = deg >= 0 ? "N" : "S";
12 } else {
13 var direction = deg >= 0 ? "E" : "W";
14 }
15
16 return degrees + "°" + minutes + "'" + seconds + "\"" + direction;
17}