热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

粗略估计GMT与纬度经度的时间偏差-roughestimateofthetimeoffsetfromGMTfromlatitudelongitude

IsthereawaytoestimatetheoffsetfromGMT(ortimezone)fromalatitudelongitude?Iveseeng

Is there a way to estimate the offset from GMT (or time zone) from a latitude/longitude? I've seen geonames, but this would need to work long term and we don't really want to rely on a web service. It'd just be used for determining whether to display "today" or "tonight" when giving information to various users so it wouldn't need to be too accurate (an hour or two off wouldn't be bad).

有没有办法从纬度/经度估算GMT(或时区)的偏移量?我见过地名,但这需要长期工作,我们真的不想依赖网络服务。它仅用于确定在向各种用户提供信息时是否显示“今天”或“今晚”,因此不需要太精确(一两个小时也不会坏)。

3 个解决方案

#1


offset = direction * longitude * 24 / 360

where direction is 1 for east, -1 for west, and longitude is in (-180,180)

东方向为1,西方方向为-1,经度方向为(-180,180)

#2


Basing the time zone on the longitude alone is wildly inaccurate outside of international waters. See the map on this page:

仅在经度上设置时区在国际水域之外是非常不准确的。查看此页面上的地图:

http://askgeo.com/database/TimeZone

The vertical colored stripes in the deep ocean are the so-called natural time zones derived from longitude alone, and the colors of the land are the actual time zones per the governing laws. You can see that they don't line up very well at all.

深海中的垂直彩色条纹是仅由经度衍生的所谓自然时区,并且土地的颜色是每个管理法则的实际时区。你可以看到他们根本没有排好队。

I actually ran into this problem while working on a different project and did substantial research and development on it. First my research:

实际上,我在处理不同的项目时遇到了这个问题,并对其进行了大量的研究和开发。首先是我的研究:

  • First, time zones are not typically encoded by just an offset from GMT (aka UTC). That fails to take into account Daylight Savings Time, and changes in the time zones over the years. Instead, time zone IDs are used to designate a geographic area in which the official clock time has been the same throughout the area for a given period of time (e.g., since 1970). The most important system of such IDs is the "Olson time zone ID" (together these IDs and their offset rules are known as the "tz database"), which is used by Linux and other Unix operating systems. Most programming languages and operating systems have native or third party support for Olson time zone IDs.
  • 首先,时区通常不仅仅由GMT(也称为UTC)的偏移量编码。这没有考虑夏令时,以及多年来时区的变化。相反,时区ID用于指定在给定时间段内(例如,自1970年以来)整个区域中官方时钟时间相同的地理区域。这种ID最重要的系统是“Olson时区ID”(这些ID和它们的偏移规则一起被称为“tz数据库”),Linux和其他Unix操作系统使用它。大多数编程语言和操作系统都对Olson时区ID具有本机或第三方支持。

In terms of existing solutions to convert latitude and longitude to time zone:

在将纬度和经度转换为时区的现有解决方案方面:

  • GeoNames.org has a vast database of point locations (centers of cities, airports, public buildings, etc.), each of which is annotated with a bunch of useful metadata, including the Olson time zone ID. And they have a nice API to let you access these via the web. The trouble is that if unless the point you are querying is right on top of a record in their database, you might get a result that is on the other side of a time zone border, or you might get no response at all if your query is far from their nearest point. The web service is also painfully slow, and they limit the number of queries you can make in a day to a relatively small number.

    GeoNames.org拥有庞大的点位置数据库(城市,机场,公共建筑等中心),每个数据库都注释了大量有用的元数据,包括奥尔森时区ID。他们有一个很好的API,让您通过网络访问这些。麻烦的是,除非您查询的点正好位于数据库中的记录之上,否则您可能会得到位于时区边界另一侧的结果,或者如果您的查询可能根本没有得到任何响应远离他们最近的点。 Web服务也非常缓慢,并且它们将一天中可以进行的查询数量限制为相对较小的数量。

  • Earth Tools (http://www.earthtools.org/webservices.htm) also has a service for this, and it is much faster than GeoNames, but it returns just an offset from GMT, not a time zone ID, and it doesn't handle Daylight Savings Time correctly for most of the world. Also, it seems to not be maintained, so I'm not sure if the data is accurate anymore (time zones change over time).

    Earth Tools(http://www.earthtools.org/webservices.htm)也有这方面的服务,它比GeoNames快得多,但它只返回GMT的偏移,而不是时区ID,它没有正确处理世界大部分地区的夏令时。此外,似乎没有维护,所以我不确定数据是否准确(时区随时间变化)。

After reviewing those options and searching for other possibilities without success, I decided to build my own solution, and have released it at:

在审查了这些选项并搜索其他可能性但没有成功之后,我决定构建自己的解决方案,并在以下位置发布:

http://askgeo.com

AskGeo is based on a time zone map of the world, so it returns a valid time zone for every valid latitude and longitude. It returns the standard Olson time zone ID (e.g., "America/Los_Angeles") used on Linux and most other operating systems and programming frameworks. It also returns the current offset, taking full account of daylight savings time.

AskGeo基于世界的时区地图,因此它为每个有效的纬度和经度返回一个有效的时区。它返回在Linux和大多数其他操作系统和编程框架上使用的标准Olson时区ID(例如,“America / Los_Angeles”)。它还会返回当前偏移量,同时充分考虑夏令时。

It is extremely easy to use and usage is documented on the main page of the site. The API supports batch queries, so if you need to do a lot of look-ups, please use the batch interface rather than bog down our servers with serial requests. The bulk queries are also much faster, so everybody wins.

它非常易于使用,并且在网站的主页上记录了使用情况。 API支持批量查询,因此如果您需要进行大量查找,请使用批处理界面,而不是使用串行请求使我们的服务器陷入困境。批量查询也快得多,所以每个人都赢了。

When we first launched this, we built it on Google App Engine (GAE) and made it free to all users. This was possible because GAE's prices were so low at that time. Since then, our server load has increased substantially and GAE's prices went way up. Both factors combined led us to switch to Amazon Web Services for hosting and to start charging for commercial use, while keeping the service free for non-profit, non-commercial open source projects, and researchers. For commercial users, we provide 1000 free queries to let potential customers evaluate the API to make sure it meets their needs. See the web site for pricing and terms.

当我们首次推出时,我们在Google App Engine(GAE)上构建了它,并向所有用户免费提供。这是可能的,因为当时GAE的价格非常低。从那时起,我们的服务器负载大幅增加,GAE的价格上涨。这两个因素的结合使我们转而使用亚马逊网络服务进行托管,并开始为商业用途收费,同时为非营利,非商业开源项目和研究人员提供免费服务。对于商业用户,我们提供1000个免费查询,让潜在客户评估API以确保其满足他们的需求。有关定价和条款,请访问网站。

The underlying library was written in Java and due to popular demand, we also released the library under a commercial license. Full documentation of the library and pricing details are on the web site.

底层库是用Java编写的,由于受欢迎的需求,我们还在商业许可下发布了库。网站上提供了完整的图书馆文档和价格详细信息。

I hope this is useful. It certainly was useful for the project I was working on.

我希望这很有用。这当然对我正在进行的项目很有用。

#3


If you know the users longitude, you completely know every aspect of time for them (neglecting some small errors like special relativity etc). The mean solar time is simply the difference of GMT and longitude (convert degrees part to minutes, 1 degree = 60 minutes). You add or subtract based on East or West. Mean solar time is basically more accurate time then time zones. Day time and night time times are variable and depend on latitude, so you use some approximations of sunrise and sunset times taking in latitude and the date and year. This alone would provide fairly accurate notion of daytime and night.

如果您知道用户的经度,那么您完全了解它们的每个方面(忽略一些小的错误,如狭义相对论等)。平均太阳时间只是GMT和经度的差异(将度数转换为分钟,1度= 60分钟)。您可以根据东方或西方进行加减。平均太阳时基本上比时区更准确。白天的时间和夜晚时间是可变的,取决于纬度,因此您可以使用纬度和日期和年份的日出和日落时间的近似值。仅这一点就可以提供相当准确的白天和黑夜概念。


推荐阅读
  • 如何使用Java获取服务器硬件信息和磁盘负载率
    本文介绍了使用Java编程语言获取服务器硬件信息和磁盘负载率的方法。首先在远程服务器上搭建一个支持服务端语言的HTTP服务,并获取服务器的磁盘信息,并将结果输出。然后在本地使用JS编写一个AJAX脚本,远程请求服务端的程序,得到结果并展示给用户。其中还介绍了如何提取硬盘序列号的方法。 ... [详细]
  • Oracle Database 10g许可授予信息及高级功能详解
    本文介绍了Oracle Database 10g许可授予信息及其中的高级功能,包括数据库优化数据包、SQL访问指导、SQL优化指导、SQL优化集和重组对象。同时提供了详细说明,指导用户在Oracle Database 10g中如何使用这些功能。 ... [详细]
  • 在重复造轮子的情况下用ProxyServlet反向代理来减少工作量
    像不少公司内部不同团队都会自己研发自己工具产品,当各个产品逐渐成熟,到达了一定的发展瓶颈,同时每个产品都有着自己的入口,用户 ... [详细]
  • 本文详细介绍了MySQL表分区的创建、增加和删除方法,包括查看分区数据量和全库数据量的方法。欢迎大家阅读并给予点评。 ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • flowable工作流 流程变量_信也科技工作流平台的技术实践
    1背景随着公司业务发展及内部业务流程诉求的增长,目前信息化系统不能够很好满足期望,主要体现如下:目前OA流程引擎无法满足企业特定业务流程需求,且移动端体 ... [详细]
  • 本文介绍了将mysql从5.6.15升级到5.7.15的详细步骤,包括关闭访问、备份旧库、备份权限、配置文件备份、关闭旧数据库、安装二进制、替换配置文件以及启动新数据库等操作。 ... [详细]
  • Imtryingtofigureoutawaytogeneratetorrentfilesfromabucket,usingtheAWSSDKforGo.我正 ... [详细]
  • WhenIusepythontoapplythepymysqlmoduletoaddafieldtoatableinthemysqldatabase,itdo ... [详细]
  • 基于Axis、XFire、CXF的webservice客户端调用示例
    本文介绍了如何使用Axis、XFire、CXF等工具来实现webservice客户端的调用,以及提供了使用Java代码进行调用的示例。示例代码中设置了服务接口类、地址,并调用了sayHello方法。 ... [详细]
  • Python爬虫中使用正则表达式的方法和注意事项
    本文介绍了在Python爬虫中使用正则表达式的方法和注意事项。首先解释了爬虫的四个主要步骤,并强调了正则表达式在数据处理中的重要性。然后详细介绍了正则表达式的概念和用法,包括检索、替换和过滤文本的功能。同时提到了re模块是Python内置的用于处理正则表达式的模块,并给出了使用正则表达式时需要注意的特殊字符转义和原始字符串的用法。通过本文的学习,读者可以掌握在Python爬虫中使用正则表达式的技巧和方法。 ... [详细]
  • PDO MySQL
    PDOMySQL如果文章有成千上万篇,该怎样保存?数据保存有多种方式,比如单机文件、单机数据库(SQLite)、网络数据库(MySQL、MariaDB)等等。根据项目来选择,做We ... [详细]
  • 如何查询zone下的表的信息
    本文介绍了如何通过TcaplusDB知识库查询zone下的表的信息。包括请求地址、GET请求参数说明、返回参数说明等内容。通过curl方法发起请求,并提供了请求示例。 ... [详细]
  • Metasploit攻击渗透实践
    本文介绍了Metasploit攻击渗透实践的内容和要求,包括主动攻击、针对浏览器和客户端的攻击,以及成功应用辅助模块的实践过程。其中涉及使用Hydra在不知道密码的情况下攻击metsploit2靶机获取密码,以及攻击浏览器中的tomcat服务的具体步骤。同时还讲解了爆破密码的方法和设置攻击目标主机的相关参数。 ... [详细]
  • baresip android编译、运行教程1语音通话
    本文介绍了如何在安卓平台上编译和运行baresip android,包括下载相关的sdk和ndk,修改ndk路径和输出目录,以及创建一个c++的安卓工程并将目录考到cpp下。详细步骤可参考给出的链接和文档。 ... [详细]
author-avatar
手机用户2502889851
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有