PHP Classes

PHP Google Maps Time Zone Convert: Get a location time zone using Google Maps API

Recommend this page to a friend!
  Info   View files Example   View files View files (69)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2022-10-21 (23 days ago) RSS 2.0 feedNot enough user ratingsTotal: 219 This week: 6All time: 8,227 This week: 135Up
Version License PHP version Categories
google-maps-timezone 1.2.8MIT/X Consortium ...5.3Localization, PHP 5, Time and Date, W..., G...
Description Author

This class can get a location time zone using Google Maps API.

It takes the geographic coordinates of a given location and sends requests to the Google Maps API to determine the time zone of a given location.

The class returns time zone for the given location, as well as that location's time offset from UTC.

Innovation Award
PHP Programming Innovation award nominee
October 2016
Number 4


Prize: One ebook of choice by Packt
Some applications need to be able to show the time for a certain event in the current user time zone. The time zone depends on the geographic location of the user.

The location of the user may be determined from the user IP address by using a geo IP database or Web service.

So, if you have the user location coordinates, you can use the Google Maps API to determine what is the user time zone.

This package can call determine the time zone of a location precisely calling the Google maps API.

Manuel Lemos
Picture of Ivan Melgrati
  Performance   Level  
Innovation award
Innovation award
Nominee: 3x

 

Details

google-time-zone

GitHub license GitHub release Total Downloads GitHub issues GitHub stars

A PHP wrapper for the Google Maps TimeZone API.

The Google Maps Time Zone API provides a simple interface to request the time zone for a location on the earth, as well as that location's time offset from UTC.

The API provides time offset data for any locations on Earch. Requests for the time zone information are made for a specific latitude/longitude pair and timestamp.

The class automates the query process and returns the name of that time zone (in different languages), the time offset from UTC, and the daylight savings offset in a user-selectable format (XML or JSON).

Developed by Ivan Melgrati

A PHP wrapper for the Google Maps Time Zone API.

Developed by Ivan Melgrati Twitter

Requirements

  • PHP >= 5.3.0
  • In order to be able to use this class, it's necessary to provide an API key or, for business clients, Client ID and signing key.

Installation

Composer

The recommended installation method is through Composer, a dependency manager for PHP. Just add imelgrat/google-time-zone to your project's composer.json file:

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

More details can be found over at Packagist.

Manually

  1. Copy `src/GoogleMapsTimeZone.php` to your codebase, perhaps to the `vendor` directory.
  2. Add the `GoogleMapsTimeZone` class to your autoloader or `require` the file directly.

Then, in order to use the GoogleMapsTimeZone class, you need to invoke the "use" operator to bring the class into skope.

<?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>';
?>

Feedback

Please open an issue to request a feature or submit a bug report. Or even if you just want to provide some feedback, I'd love to hear. I'm also available on Twitter as @imelgrat.

Contributing

  1. Fork it.
  2. Create your feature branch (`git checkout -b my-new-feature`).
  3. Commit your changes (`git commit -am 'Added some feature'`).
  4. Push to the branch (`git push origin my-new-feature`).
  5. Create a new Pull Request.
  Files folder image Files  
File Role Description
Files folder imagedocs (2 files, 9 directories)
Files folder imageexamples (2 files)
Files folder imagesrc (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpdoc.dist.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file VERSION Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:219
This week:6
All time:8,227
This week:135Up

For more information send a message to info at phpclasses dot org.