获取特定时区内的任何纬度和经度对应的方法?

huangapple go评论87阅读模式
英文:

How to get any Latitude and Longitude pair within a timezone?

问题

我正在使用Android设备上的java方法 TimeZone.getDefault() 来获取我的当前时区。

我需要提取在时区边界内的任何纬度经度对,最好是中心,但不一定要精确。

是否有时区边界数据或其他方法来实现这一目标?

原因:我有一个第三方API,我需要在某些功能中使用它,虽然该API在其功能方面表现良好,但不再处于活跃开发状态,也没有开源。

该API需要纬度、经度对来确定时区,而没有公开的替代方法来提供时区信息。如果有可能,我宁愿不向用户请求精确位置权限。

英文:

I am using the java method TimeZone.getDefault() on an Android device to get my current timezone.

I need to extract any latitude longitude pair within the boundaries of the timezone. preferably the center, but it doesn't have to be exact.

Is there some Timezone boundaries data somewhere or some other way to achieve this?

Rationale: I have a 3rd party API that I am required to use for certain functionality,
and while the API works well for what it does, it is no longer in active development and is not open-sourced.

The API requires a Latitude, Longitude pair to determine timezone, and has no public alternative to provide a timezone instead.
I would rather not ask my users for location permission for an exact location if I can get away with it.

答案1

得分: 1

我可以想到两个相关的数据源,在这里可能会有用:

  • IANA TZDB 包含两个文件,zone1970.tabzone.tab。这些列表旨在帮助选择时区,并包含了每个用作时区参考点的城市的坐标。

  • 时区边界构建器 项目包含了每个时区的大致地理边界的形状文件。许多库(如此处所列)使用这些文件,这些库专注于将纬度/经度转换为时区的问题。您似乎对反向操作感兴趣,这将需要您进行一些分析工作。基本上,您需要使用该项目的多边形形状文件,并从与所涉及时区相关联的多边形中随机选择一个点。

无论使用哪种方法,您可能首先需要将别名解析为它们的规范对应项。例如,如果您有 US/Eastern,您需要在尝试在任何数据源中查找之前将其解析为 America/New_York

英文:

I can think of two relevant data sources that would be useful here:

  • The IANA TZDB contains two files, zone1970.tab and zone.tab. These lists are designed to assist with time zone selection, and contain coordinates for each of the cites that serve as reference points, for the time zones listed.

  • The Timezone Boundary Builder project has shapefiles containing the approximate geographic boundaries for each time zone. This is used by many libraries (as listed here) that are focused on the problem of lat/lon to timezone. You appear to be interested in going the other direction, which will require some analysis work on your part. Basically, you would need to use the polygon shapefiles from that project and pick a point at random from within a polygon associated with the time zone in question.

With either approach, you may first need to resolve aliases to their canonical counterparts. For example, if you have US/Eastern, you'd need to resolve that to America/New_York before attempting to look it up in either data source.

huangapple
  • 本文由 发表于 2020年8月2日 21:22:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/63216507.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定