如何从机场代码(IATA/FAA)获取时区 [英] How to get timezone from airport code (IATA/FAA)
问题描述
我正在尝试制作一个PHP函数,该函数返回给定机场代码(IATA/FAA)的UTC时区.
I am trying to make a PHP function that returns the UTC timezone for a given airport code (IATA/FAA).
该函数应该执行的操作是这样的:
What the function should do is something like this:
echo getTimezoneFromAirportCode("CPH"); // +1
echo getTimezoneFromAirportCode("CXI"); // +14
要实现此功能,我需要列出所有机场代码及其时区.
To make this function I need a list of all aiport codes and their timezones.
通过搜索,我找到了以下列表: http://openflights.org/data.html )
By searching a bit I found this list: https://sourceforge.net/p/openflights/code/HEAD/tree/openflights/data/airports.dat?format=raw (Source: http://openflights.org/data.html)
在列表中查找了几个机场代码后,我发现某些数据不正确.例如,它将CXI
列出为UTC -12
时区-根据此页面不正确.
After looking up a couple of airport codes in the list I found out that some of the data was incorrect. For instance it lists CXI
to be in the UTC -12
timezone - which according to this page is incorrect.
你们中的任何人都知道一个提供执行getTimezoneFromAirportCode
功能所需数据的公共列表吗?
Does any of you know a public list that provides the data needed to make the getTimezoneFromAirportCode
function?
推荐答案
我设法找到了解决该问题的方法.通过flightstats.com API,可以免费但有限地访问完整的机场数据库: https://developer.flightstats.com/api-docs/airports/v1
I've managed to find a solution to the issue. Through the flightstats.com API it is possible to get a free but limited access to a complete airport database: https://developer.flightstats.com/api-docs/airports/v1
API以以下格式返回所有活动/不活动的机场:
The API returns all active/inactive airports in the following format:
{
"fs": "LAX",
"iata": "LAX",
"icao": "KLAX",
"faa": "LAX",
"name": "Los Angeles International Airport",
"street1": "One World Way",
"street2": "",
"city": "Los Angeles",
"cityCode": "LAX",
"stateCode": "CA",
"postalCode": "90045-5803",
"countryCode": "US",
"countryName": "United States",
"regionName": "North America",
"timeZoneRegionName": "America/Los_Angeles",
"weatherZone": "CAZ041",
"localTime": "2014-06-20T06:00:50.439",
"utcOffsetHours": -7,
"latitude": 33.943399,
"longitude": -118.408279,
"elevationFeet": 126,
"classification": 1,
"active": true,
"delayIndexUrl": "https://api.flightstats.com/flex/delayindex/rest/v1/json/airports/LAX?codeType=fs",
"weatherUrl": "https://api.flightstats.com/flex/weather/rest/v1/json/all/LAX?codeType=fs"
}
这正是我要实现其功能所需的数据:
This was exactly the data I needed to be able to make my function:
echo getTimezoneFromAirportCode("LAX"); // -7
可通过以下GET请求获得数据:
The data is available through the following GET request:
https://api.flightstats.com/flex/airports/rest/v1/json/all?appId=[appId]&appKey=[appKey]
在此处创建免费的flightstats.com开发人员帐户后,将提供
[appId]
和[appKey]
: https://developer.flightstats.com/signup
[appId]
and [appKey]
will be provided after creating a free flightstats.com developer account here: https://developer.flightstats.com/signup
这篇关于如何从机场代码(IATA/FAA)获取时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!