File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,13 +5,13 @@ const getDirection = (degrees: number, isLongitude: boolean) =>
55 degrees > 0 ? ( isLongitude ? "E" : "N" ) : isLongitude ? "W" : "S" ;
66
77// adapted from http://stackoverflow.com/a/5786281/2546338
8- const formatDegrees = ( degrees : number , isLongitude : boolean ) =>
9- ` ${ 0 | degrees } ° ${
10- 0 | ( ( ( degrees < 0 ? ( degrees = - degrees ) : degrees ) % 1 ) * 60 )
11- } ' ${ 0 | ( ( ( degrees * 60 ) % 1 ) * 60 ) } " ${ getDirection (
12- degrees ,
13- isLongitude ,
14- ) } ` ;
8+ const formatDegrees = ( value : number , isLongitude : boolean ) => {
9+ const abs = Math . abs ( value ) ;
10+ const degrees = Math . trunc ( value ) ;
11+ const minutes = Math . floor ( ( abs % 1 ) * 60 ) ;
12+ const seconds = Math . floor ( ( ( abs * 60 ) % 1 ) * 60 ) ;
13+ return ` ${ degrees } ° ${ minutes } ' ${ seconds } " ${ getDirection ( value , isLongitude ) } ` ;
14+ } ;
1515
1616export const Demo = ( ) => {
1717 const {
You can’t perform that action at this time.
0 commit comments