复杂日期到纬度反转功能 [英] Complicated Date to Lat Reverse function

查看:47
本文介绍了复杂日期到纬度反转功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在撰写使用Google地图的时间表。我有一个函数

将日期时间转换为纬度坐标。此函数用于在时间轴上绘制

标记。我需要一个反向函数来将

纬度坐标转换回准确的日期时间。然后,当时间轴放大或缩小时,或者如果移动时,我可以在视口中检测到

天/小时。我不能使用javascript日期函数,因为这个

时间轴最终将用于BC和AD年。


地图是准确的,直到缩放级别6
http://www.wwcompclub.org/ worldwar / w .... php?year = 1865


此外,添加事件和编辑事件表单不起作用,所以不要打扰

尝试。


Days [] []是每个月的数组,包含每月

的天数。

所以

天[1] .length = 31;



天[1] [30] = 31st;


HourConst = 0.00035673379898071291666666666666667;

byear = 1808;

ayear = 1922;


函数isLeapYear(年){//此函数似乎工作正常

yr = parseInt(年);

if(b)是%4!= 0)返回false;

else if(yr%400 == 0)返回true;
否则if(yr%100 == 0)返回false;

else返回false;

}

函数GetLat(syear,smonth,sday,shour){//这个功能很棒


if(isLeapYear(syear)){

LeapYear = HourConst * 24 ;

}其他{

LeapYear = 0;

}


MonthCalc = 0; < ($ = 0;
;(i = 0;我< smonth; i ++){

if(isLeapYear(syear)&& i == 1){

DayVar = 29;

}否则if (i == 1){

DayVar = 28;

}否则{

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;

返回TLlat;


}

//这是我目前正在使用的功能,但是由于飞跃而几天不会导致

//年数和到期到每个月的不同天数

函数GetDate(lat){//这个函数应该与

" GetLat"相反。功能


RelLat = parseFloat(lat)+ 180; //添加180度,所以我们不是

除以否定数字


YRem = RelLat%(HourConst * 8760);

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


MRem = YRem%(HourConst * 672); //(最少28天)

月= 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;

小时= 1;

}

if(年>一年){

年=年;

月= 1;

日= 1;

小时= 1;

}

this.Years =年份;

this.Months =月;

this.Days = Day;

this.Hours =小时;

}

解决方案

JRS:文章< 11 *************** *******@f14g2000cwb.googlegroups .com>

,日期为星期二,2006年1月10日09:06:34本地,见于

news:comp。 lang.javascript,jshanman< jc ****** @ sbcglobal.net>发表:

我正在编写一个使用谷歌地图的时间表。我有一个功能,它将日期时间转换为纬度坐标。此功能用于在时间轴上绘制标记。我需要一个反向功能来将
纬度坐标转换回准确的日期时间。然后,当时间轴放大或缩小时,或者如果它被移动,我可以在视口中检测到
日/小时。我不能使用javascript日期函数,因为这个
时间轴最终将用于BC和AD年。


从1970-01-01.0格林威治标准时间开始,Javascript日期为+ -10 ^ 8天。

超过四分之一零年的每一年都是百万年。


在发布之前,你应该阅读新闻组常见问题;见下文。

地图是准确的,直到缩放级别6
http://www.wwcompclub.org/worldwar/w....php?year=1865

此外,添加活动并且编辑活动表格不起作用,所以不要打扰
尝试。

Days [] []是每个月的数组,包含
每个月。
所以
Days [1] .length = 31;

Days [1] [30] =" 31st" ;;


不必要。可以很容易地计算出月和长度。


HourConst = 0.00035673379898071291666666666666667;


目前还不清楚它是什么,或者输入是否正确。

它应该作为一个不言自明的表达式输入,并且计算了

一次。

byear = 1808;
ayear = 1922;

函数isLeapYear(年){//这个函数似乎工作正常
yr = parseInt(年);


如果年份恰好是一个前导零的字符串,那将导致

错误的结果。如果它是一个没有的字符串,一元+更好。如果它是一个

数字,parseInt应强制转换为字符串并返回。如果没有必要,切勿使用

parseInt或parseFloat;永远不要使用parseInt和

只有一个参数,除非你能证明这样做是安全的。

if(yr%4!= 0)返回false;
else if(yr%400 == 0)返回true;
else if(yr%100 == 0)return false;
else return false;
}




速度差异难以察觉;但为了提高效率,应该在400测试之前进行
100测试。但是,我怀疑是否真的需要

功能。


//考虑:Leap =!new Date(年,0,31 + 366)。 getMonth()

其余的看起来很糟糕;但是你的实际意图并不清楚。


在用一种语言写作之前,你应该阅读它。


如果要线性地使用纬度取决于绝对时间YMD hms ms,


Lat = A + B *新日期(Y,M-1,D,h,m,s,ms)

DOb =新日期((Lat-A)/ B)

其中A是1970.0 GMT的纬度,B是180 / 1e13或

更小; DOb是日期对象。


请注意,上述内容可能会有一个小错误,具体取决于浏览器的位置。相反,使用IIRC,

A + B *新日期(Date.UTC(Y,M-1,D,h,m,s,ms))

以及用于扩展DOb的UTC功能,并且无需担心。

它也会更快地执行。除非你想要线性依赖

浏览器'*民用*时间。


这当然会使用Proleptic Astronomical Gregorian日期;但是

你可以找到Julian< - >格里高利转换(通过下面)。


当然不要使用getYear,除非你必须允许浏览器

没有getFullYear,在这种情况下只使用它功能getFY(")。


您可能需要陷入初级中心岁月;增加400年并减去

4800个月。或者不要测试,如果你能接受

范围限制,请+120000 -1440000。


-

?约翰斯托克顿,英国萨里。 ?@merlyn.demon.co.uk Turnpike v4.00 IE 4?

< URL:http://www.jibbering.com/faq/> JL / RC:新闻常见问题:comp.lang.javascript

< URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr数学,日期,来源。

< URL:http://www.merlyn.demon.co.uk/> TP / BP / Delphi / jscr /& c,FAQ项目,链接。


感谢您的回复。我从来没有使用过javascript日期函数,

所以我会读到它。我没有意识到你可以在1970年之前去购买
。我是一个随时随地学习的人。程序员。

HourConst = 0.00035673379898071291666666666666667;




这是地图上的长度,纬度为一小时。我已经使用DIV的宽度和最高缩放级别的地图的纬度界限来计算这个
,以获得所需的小时数

显示(~48小时)。


我已经在我的功能中发现了其他几个问题,因为我发布了

这个。它现在工作得好多了,但可能没那么高效。


我的问题是:

TLlat =

((RelYear *((HourConst * 8760)+ LeapYear))+(monthFacto r)+(sday *(24 * HourConst))+ *(shour * HourConst)) - 180;

如果给定的年份是闰年,那么它假设每一年前的每一年都是一个闰年。因为我已经纠正了这个问题,所以看起来只需要更多的错误就可以了。


这就是现在的位置:

NumOfLP =((最后 - 首先)/ 4)+1; //最后&&首先=

在给定范围内的最后/第一次闰年

RelYear = syear - byear; // syear是给定的开始年份,byear是

第一年的范围

RelYear = RelYear - NumOfLP;

TLlat =( (NumOfLP *(HourConst * 8784))+

(RelYear *(HourConst * 8760))+ monthFactor +(sday *(24 * H ourConst))+(shour * HourConst)) - 180;


再次感谢您花时间回复。我将阅读有关日期

函数的信息,看看我是否可以将它应用到我的脚本中以使它们更有效。


2006年1月10日09:06:34 -0800,jshanman < jc ****** @ sbcglobal.net>

写道:

我正在编写一个使用谷歌地图的时间表。我有一个功能,它将日期时间转换为纬度坐标。此功能用于在时间轴上绘制标记。我需要一个反向功能来将
纬度坐标转换回准确的日期时间。然后,当时间轴放大或缩小时,或者如果它被移动,我可以在视口中检测到
日/小时。我不能使用javascript日期函数,因为这个
时间轴最终将用于BC和AD年。



没有评论你的代码,但我认为你的意思是经度,而不是纬度。


当您计算

亮/暗区域时,这种计算会非常有趣!


学生项目:


用UTC格式的

时间戳计算记录光亮或黑暗的仪器的位置,没有其他信息


这是一个真实的项目,我们几年前做过一个仪器

包装轻便,可以由信天翁携带!


Paul


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;
}

解决方案

JRS: In article <11**********************@f14g2000cwb.googlegroups .com>
, dated Tue, 10 Jan 2006 09:06:34 local, seen in
news:comp.lang.javascript, jshanman <jc******@sbcglobal.net> posted :

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.
Javascript dates have a span of +-10^8 days from 1970-01-01.0 GMT.
That''s more than a quarter of a million years each side of Year Zero.

Before posting, you should read the newsgroup FAQ; see below.
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";
Unnecessary. Suffices and month-length can easily be computed.

HourConst = 0.00035673379898071291666666666666667;
It''s not clear what that might be, or whether it is correctly entered.
It should be entered as a self-explanatory expression, and calculated
once.
byear = 1808;
ayear = 1922;

function isLeapYear(year) { //this function seems to work OK
yr = parseInt(year);
If year happens to be a string with a leading zero, that will give a
wrong result. If it''s a string without, unary + is better. If it''s a
number, parseInt should force conversion to string and back. Never use
parseInt or parseFloat when it''s not necessary; never use parseInt with
only one parameter unless you can prove it safe to do so.
if (yr % 4 != 0) return false;
else if (yr % 400 == 0) return true;
else if (yr % 100 == 0) return false;
else return false;
}



The difference in speed will be imperceptible; but for efficiency the
100 test should precede the 400 test. However, I doubt whether the
function is really needed.

// Consider: Leap = !new Date(year, 0, 31+366).getMonth()
The rest looks as bad; but your actual intentions are not clear.

Before writing in a language, you should read about it.

If latitude is to be linearly dependent on absolute time Y M D h m s ms,

Lat = A + B*new Date(Y, M-1, D, h, m, s, ms)
DOb = new Date((Lat-A)/B)
where A is the Lat for 1970.0 GMT and B is something like 180/1e13 or
smaller; DOb is a Date Object.

Note that the above may have a small error, depending on the location of
the browser. Use, instead, IIRC,
A + B*new Date(Date.UTC(Y, M-1, D, h, m, s, ms))
and the UTC functions to expand DOb, and there''ll be no need to worry.
Also it will execute faster. Unless you want linear dependence on
browser''s *civil* time.

That will, of course, use Proleptic Astronomical Gregorian dates; but
you can find Julian <-> Gregorian conversion (via below).

Do not, of course, use getYear, unless you must allow for browsers
without getFullYear in which case use it only in function getFY (").

You may need to trap first-centade years; add 400 years and subtract
4800 months. Or don''t test, and +120000 -1440000 if you can accept the
range limitation.

--
? John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ?
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.


Thank you for the reply. I''ve never used the javascript date function,
so I will read up about it. I did not realize that you could go
earlier then 1970. I''m a "learn as I go" programmer.

HourConst = 0.00035673379898071291666666666666667;



This is the length on the map, in Latitude of one hour. I''ve
calculated this using the width of the DIV and the latitude bounds of
the map at the highest zoom level to get the desired number of hours
displayed (~48 hours).

I''ve found several other problems in my functions since I''ve posted
this. It is working much better now, but probably not as efficient as
it could be.

My problem was:
TLlat =
((RelYear*((HourConst*8760)+LeapYear))+(monthFacto r)+(sday*(24*HourConst))+*(shour*HourConst))-180;
If the given year was a leap year, it was assuming every yar before it
was a leap year as well. Since I''ve corrected this, It appears to be
accurate with just a few more bugs to work out.

This is now in its place:
NumOfLP = ((LastLY - FirstLY)/4)+1; //LastLY && FirstLY = the
last/first leap years in the given range
RelYear = syear - byear; //syear is the given start year, byear is the
first year in the range
RelYear = RelYear - NumOfLP;
TLlat = ((NumOfLP*(HourConst*8784)) +
(RelYear*(HourConst*8760))+monthFactor+(sday*(24*H ourConst))+(shour*HourConst))-180;

Thanks again for taking the time to reply. I will read about the date
function to see if I can apply it to my scripts to make them more
efficient.


On 10 Jan 2006 09:06:34 -0800, "jshanman" <jc******@sbcglobal.net>
wrote:

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.


No comment on your code, but I think you mean Longitude, not Latitude.

This sort of calculation gets to be really fun when you are computing
light/dark areas!

Project for the Student:

Calculate the position of an instrument that logs light or dark with a
timestamp in UTC, and no other information

This is a real project that we did some years ago for an instrument
package light enough to be carried by an albatross!

Paul


这篇关于复杂日期到纬度反转功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆