jacky

A technique blog for jacky

here are my artitles about work(embeded system develop, docker, etc.) and life(cook, hiking)


使用zonedetect获取当前位置的时区

使用zoneDetect获取当前位置的时区

获取时区的方案分为在线版和离线版,在嵌入式设备上一般使用离线版本。参考信息如下:

Time Zone Location Web Services

Raw Time Zone Boundary Data

  • Timezone Boundary Builder - builds time zone shapefiles from OpenStreetMaps map data. Includes territorial waters near coastlines.

The following projects have previously been sources of time zone boundary data, but are no longer actively maintained.

Time Zone Geolocation Offline Implementations

Implementations that use the Timezone Boundary Builder data

Implementations that use the older tz_world data

Libraries that call one of the web services

  • timezone - Ruby gem that calls GeoNames
  • AskGeo has its own libraries for calling from Java or .Net
  • GeoNames has client libraries for just about everything

Other Ideas

Please update this list if you know of any others

Also, note that the nearest-city approach may not yield the “correct” result, just an approximation.

Conversion To Windows Zones

Most of the methods listed will return an IANA time zone id. If you need to convert to a Windows time zone for use with the TimeZoneInfo class in .NET, use the TimeZoneConverter library.

Don’t use zone.tab

The tz database includes a file called zone.tab. This file is primarily used to present a list of time zones for a user to pick from. It includes the latitude and longitude coordinates for the point of reference for each time zone. This allows a map to be created highlighting these points. For example, see the interactive map shown on the moment-timezone home page.

While it may be tempting to use this data to resolve the time zone from a latitude and longitude coordinates, consider that these are points - not boundaries. The best one could do would be to determine the closest point, which in many cases will not be the correct point.

Consider the following example:

Time Zone Example Art

The two squares represent different time zones, where the black dot in each square is the reference location, such as what can be found in zone.tab. The blue dot represents the location we are attempting to find a time zone for. Clearly, this location is within the orange zone on the left, but if we just look at closest distance to the reference point, it will resolve to the greenish zone on the right.

shareimprove this answer

edited May 11 at 3:58

通过查阅上述的开源库,js版,python版和c版都已经测试成功,java和.net由于开发环境限制暂时不考虑测试。

js版测试步骤

只需要npm install [库名称],然后编写.js文件,使用node [.js文件]即可运行并检查结果。

C版-ZoneDetect-测试步骤

需要先编译出library中的动态库

make

生成libzoneDetect.so, 然后编译demo.,

gcc -o demo dmeo.c -L. -lzoneDetect

然后执行测试

./demo ../library/*.bin lat lon

c版-ZoneDetect-交叉编译测试

使用arm-linux-gnueabihf-gcc交叉编译工具链编译

make之前,修改Makefile中的CC

CC=arm-linux-gnueabihf-gcc

然后make生成so库

编译测试文件时,注意需要带上-lm(math库)

gcc -o demo demo.c -L. -lzoneDetect -lm

在设备上可以执行demo,还需要添加时区名->utc差值的接口,可参考python版本的实现思路

最近的文章

How to convert hgt to osm

#how to convert hgt from SRTM to osmtools used:phyghtmap homePage manPage###environment reference:ubuntu16.04+python3.5DownloadAt the moment, you have the choice between two different distribution types: Source distibution: phyghtmap_2.20.orig.t...…

继续阅读
更早的文章

Raspberrypi使用ssh中文显示和编辑的问题

环境1.raspberryPi 3B+, python2.7 + python3.62.mac OSX 10.13.3 ssh(osx terminal), Termius使用OSX自带的ssh连接树莓派的时候,ssh中不能输入和输出中文,使用vnc打开terminal也一样相关error:SyntaxError: Non-ASCII character ‘\xe4’ in file test1.py on line 2, but no encoding declared; see htt...…

继续阅读