简体   繁体   中英

Is there a way to read the coordinate information from zone.tab using Linux command line or C++

I need to approximate geolocation coordinates of an embedded linux device based soley on its timezone. This is a stand alone device which is not connected to the inetrnet and therefore must only use data stored on the local filesystem.

The zone.tab database stores coordinate information (Lattitude & Longitude) for the principal city in each timezone, however I have not found an easy interface to read these using c++.

PHP provides an interface DateTimeZone::getLocation to access this information. Is there a C++ or Linux system interface to do the same?

Obviuosly I can write my own interface which reads the file and converts the data, but I would prefer to implement a more standardised solution.

On Linux systems, the zone.tab file is deployed to /usr/share/zoneinfo , where programs like tzselect use it directly. It is not exposed through a common OS-level API.

PHP does not use this information. It has its own tzdata compiler, and includes the zone info (including zone.tab) in the timezonedb bundle - which is embedded in each release of PHP, or can be downloaded separately from PECL . Unless you are already shipping PHP with your system, you probably don't want to get it from here.

Ultimately, if you don't have /usr/share/zoneinfo/zone.tab on your machine, and you need access to it, then you should get it from the tzdata distribution directly.

But seriously - getting lat/lon of a device based on what the user of the device picked for a time zone is going to be just asking for trouble. Keep in mind that the geographical region of a time zone can span hundreds or thousands of miles from its point of reference. Also, there are plenty of administrative zones that have no fixed location reference (such as Etc/GMT+2 ). Not every valid time zone is in zone.tab.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM