沃梦达 / 编程问答 / php问题 / 正文

如何从机场代码 (IATA/FAA) 获取时区

How to get timezone from airport code (IATA/FAA)(如何从机场代码 (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) 获取时区

基础教程推荐