幸福伝説

Decimal Degree to DMS 본문

Language/JavaScript

Decimal Degree to DMS

행복전설 2014. 11. 6. 14:39

/* This is the pseudocode you need to follow:
 * It's a modified version from
 * http://en.wikipedia.org/wiki/Geographic_coordinate_conversion#Conversion_from_Decimal_Degree_to_DMS

function deg_to_dms ( degfloat )
   Compute degrees, minutes and seconds:
   deg ← integerpart ( degfloat )
   minfloat ← 60 * ( degfloat - deg )
   min ← integerpart ( minfloat )
   secfloat ← 60 * ( minfloat - min )
   Round seconds to desired accuracy:
   secfloat ← round( secfloat, digits )
   After rounding, the seconds might become 60. These two
   if-tests are not necessary if no rounding is done.
   if secfloat = 60
      min ← min + 1
      secfloat ← 0
   end if
   if min = 60
      deg ← deg + 1
      min ← 0
   end if
   Return output:
   return ( deg, min, secfloat )
end function
*/

 

function deg_to_dms (deg) {
   var d = Math.floor (deg);
   var minfloat = (deg-d)*60;
   var m = Math.floor(minfloat);
   var secfloat = (minfloat-m)*60;
   var s = Math.round(secfloat);
   // After rounding, the seconds might become 60. These two
   // if-tests are not necessary if no rounding is done.
   if (s==60) {
     m++;
     s=0;
   }
   if (m==60) {
     d++;
     m=0;
   }
   return ("" + d + ":" + m + ":" + s);
}

'Language > JavaScript' 카테고리의 다른 글

자바스크립트에서 OS 시스템 환경변수 사용하기  (0) 2015.06.10
proj4js  (0) 2014.10.09
RequreJS 사용 방법 정리  (0) 2014.08.26
RequireJS 살펴보기  (0) 2014.08.26
Internet Explorer full screen mode?  (0) 2014.08.25