imelgrat/google-time-zone

Google Maps TimeZone API 的 PHP 封装。

1.5.1 2018-08-28 11:26 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:31:19 UTC


README

GitHub license GitHub release Total Downloads GitHub issues GitHub stars

Google Maps TimeZone API 的 PHP 封装。

Google Maps Time Zone API 提供了一个简单的接口,用于请求地球上某个位置的时区,以及该位置相对于 UTC 的时间偏移。

API 为地球上的任何位置提供时间偏移数据。时区信息请求针对特定的经纬度和时间戳。

该类自动执行查询过程,并以用户可选择的形式(XML 或 JSON)返回该时区的名称(不同语言)、UTC 时间偏移和夏令时偏移。

Ivan Melgrati 开发

======= Google Maps Time Zone API 的 PHP 封装。

Ivan Melgrati 开发 Twitter

要求

  • PHP >= 5.3.0
  • 为了能够使用此类,需要提供 API 密钥,或者对于商业客户,需要提供客户端 ID 和签名密钥。

安装

Composer

推荐的安装方法是通过 Composer,一个 PHP 依赖管理器。只需将 imelgrat/google-time-zone 添加到项目中的 composer.json 文件。

{
    "require": {
        "imelgrat/google-time-zone": "*"
    }
}

更多详情 可在 Packagist 上找到。

手动安装

  1. src/GoogleMapsTimeZone.php 复制到您的代码库中,例如到 vendor 目录。
  2. GoogleMapsTimeZone 类添加到您的自动加载器或直接 require 文件。

然后,为了使用 GoogleMapsTimeZone 类,需要使用 "use" 操作符将类引入作用域。

<?php
    use imelgrat\GoogleMapsTimeZone\GoogleMapsTimeZone;
	require_once ('../src/GoogleMapsTimeZone.php');
    
    /**
     * All queries require an API key from Google
     * @link https://developers.google.com/maps/documentation/timezone/get-api-key
     * */
	define('API_KEY', 'YOUR API KEY HERE');

	// Initialize GoogleMapsTimeZone object (New York City coordinates)
	$timezone_object = new GoogleMapsTimeZone(40.730610, -73.935242, 0, GoogleMapsTimeZone::FORMAT_JSON);
    
    // Set Google API key
	$timezone_object->setApiKey(API_KEY);
    
    // Perform query 
	$timezone_data = $timezone_object->queryTimeZone();
	
	echo '<pre>';
	print_r($timezone_data);
	echo '</pre>';
?>

反馈

请创建一个问题来请求功能或提交错误报告。或者如果您只是想提供一些反馈,我也非常乐意听。您也可以在 Twitter 上关注我 @imelgrat

贡献

  1. 创建分支。
  2. 创建您的功能分支(git checkout -b my-new-feature)。
  3. 提交您的更改(git commit -am 'Added some feature')。
  4. 将更改推送到分支(git push origin my-new-feature)。
  5. 创建一个新的 Pull Request。