MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Javascript Latitude to Date function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63716] Javascript Latitude to Date function
  • From: "jshanman" <jcshanks at sbcglobal.net>
  • Date: Wed, 11 Jan 2006 06:49:38 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

I am writing a timeline that uses Google Maps. I have a function that
converts a date time to latitude coords.  This function is used to draw

the markers on the timeline.  I need a reverse function to convert a
latitude coord back to an accurate date time.  Then I could detect the
day/hour in the viewport when the timeline is zoomed in or out, or if
it is moved. I cannot use the javascript date functions because this
timeline will eventually be used for BC and AD years.


The map is accurate until zoom level 6
http://www.wwcompclub.org/worldwar/wiki/map.php?year=1865


Also, the add event and edit event forms don't work, so don't bother
trying.


Days[][] is an array of each month containing the number of days in
each month.
So
Days[1].length = 31;
And
Days[1][30] = "31st";


 HourConst = 0.00035673379898071291666666666666667;
 byear = 1808;
 ayear = 1922;


function isLeapYear(year) { //this function seems to work OK
  yr = parseInt(year);
  if (yr % 4 != 0)   return false;
  else if (yr % 400 == 0) return true;
  else if (yr % 100 == 0) return false;
  else return false;



}


function GetLat (syear,smonth,sday,shour) { //this function works great


  if (isLeapYear(syear)) {
     LeapYear = HourConst*24;
  } else {
     LeapYear = 0;
  }


  MonthCalc = 0;


  for (i = 0; i < smonth; i++) {
     if (isLeapYear(syear) && i == 1) {
        DayVar = 29;
     } else if (i == 1) {
        DayVar = 28;
     } else {
        DayVar = Days[i].length;
     }
      MonthCalc += DayVar;
  }


  monthFactor = (HourConst*24)*MonthCalc;


  RelYear = syear - byear;
  TLlat =
((RelYear*((HourConst*8760)+LeapYear))+(monthFactor)+(sday*(24*HourConst))+­(shour*HourConst))-180;

  return TLlat;



}


//this is the function I am currently using, but it is inaccurate by a
few days due to leap
//years and due to the differant number of days in each month

function GetDate(lat) { //this function should be a reverse of the
"GetLat" function


   RelLat = parseFloat(lat) + 180; //add 180 degress so we are not
dividing negitive numbers


   YRem = RelLat%(HourConst*8760);
   Year = parseInt((RelLat/(HourConst*8760))+byear);


   MRem = YRem%(HourConst*672); //(min 28 days)
   Month = parseInt(YRem/(HourConst*672));


   DRem = MRem%(HourConst*24);
   Day = parseInt(MRem/(HourConst*24));
   Hour = parseInt(DRem/HourConst);


   if (Year < byear) {
      Year = byear;
      Month = 1;
      Day = 1;
      Hour = 1;
   }
   if (Year > ayear) {
     Year = ayear;
      Month = 1;
      Day = 1;
     Hour = 1;
   }
   this.Years = Year;
   this.Months = Month;
   this.Days = Day; 
   this.Hours = Hour; 
 }


  • Prev by Date: Re: NDSolve::ndsz question
  • Next by Date: Re: Puzzle Challenge
  • Previous by thread: Re: units
  • Next by thread: select and paste issue