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/w....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))+(monthFacto r)+(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;

}