How to get timezone from airport code (IATA/FAA)(如何从机场代码 (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.
通过搜索我找到了这个列表:https://sourceforge.net/p/openflights/code/HEAD/tree/openflights/data/airports.dat?format=raw(来源: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]
[appId]
和 [appKey]
将在此处创建免费的 flightstats.com 开发者帐户后提供: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) 获取时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从机场代码 (IATA/FAA) 获取时区
基础教程推荐
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01