热门标签 | 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分钟)。您可以根据东方或西方进行加减。平均太阳时基本上比时区更准确。白天的时间和夜晚时间是可变的,取决于纬度,因此您可以使用纬度和日期和年份的日出和日落时间的近似值。仅这一点就可以提供相当准确的白天和黑夜概念。


推荐阅读
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • 微软头条实习生分享深度学习自学指南
    本文介绍了一位微软头条实习生自学深度学习的经验分享,包括学习资源推荐、重要基础知识的学习要点等。作者强调了学好Python和数学基础的重要性,并提供了一些建议。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • ALTERTABLE通过更改、添加、除去列和约束,或者通过启用或禁用约束和触发器来更改表的定义。语法ALTERTABLEtable{[ALTERCOLUMNcolu ... [详细]
  • 深度学习中的Vision Transformer (ViT)详解
    本文详细介绍了深度学习中的Vision Transformer (ViT)方法。首先介绍了相关工作和ViT的基本原理,包括图像块嵌入、可学习的嵌入、位置嵌入和Transformer编码器等。接着讨论了ViT的张量维度变化、归纳偏置与混合架构、微调及更高分辨率等方面。最后给出了实验结果和相关代码的链接。本文的研究表明,对于CV任务,直接应用纯Transformer架构于图像块序列是可行的,无需依赖于卷积网络。 ... [详细]
  • Python爬虫中使用正则表达式的方法和注意事项
    本文介绍了在Python爬虫中使用正则表达式的方法和注意事项。首先解释了爬虫的四个主要步骤,并强调了正则表达式在数据处理中的重要性。然后详细介绍了正则表达式的概念和用法,包括检索、替换和过滤文本的功能。同时提到了re模块是Python内置的用于处理正则表达式的模块,并给出了使用正则表达式时需要注意的特殊字符转义和原始字符串的用法。通过本文的学习,读者可以掌握在Python爬虫中使用正则表达式的技巧和方法。 ... [详细]
  • 生成式对抗网络模型综述摘要生成式对抗网络模型(GAN)是基于深度学习的一种强大的生成模型,可以应用于计算机视觉、自然语言处理、半监督学习等重要领域。生成式对抗网络 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • 本文介绍了brain的意思、读音、翻译、用法、发音、词组、同反义词等内容,以及脑新东方在线英语词典的相关信息。还包括了brain的词汇搭配、形容词和名词的用法,以及与brain相关的短语和词组。此外,还介绍了与brain相关的医学术语和智囊团等相关内容。 ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • [译]技术公司十年经验的职场生涯回顾
    本文是一位在技术公司工作十年的职场人士对自己职业生涯的总结回顾。她的职业规划与众不同,令人深思又有趣。其中涉及到的内容有机器学习、创新创业以及引用了女性主义者在TED演讲中的部分讲义。文章表达了对职业生涯的愿望和希望,认为人类有能力不断改善自己。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 如何用UE4制作2D游戏文档——计算篇
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了如何用UE4制作2D游戏文档——计算篇相关的知识,希望对你有一定的参考价值。 ... [详细]
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社区 版权所有