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    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 221 All time: 8,244 This week: 132Up
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  
Name: Ivan Melgrati is available for providing paid consulting. Contact Ivan Melgrati .
Classes: 11 packages by
Country: Argentina Argentina
Age: 48
All time rank: 1973 in Argentina Argentina
Week rank: 90 Up2 in Argentina Argentina Up
Innovation award
Innovation award
Nominee: 3x

Example

<?php
   
/**
     * This section includes a sample query that demonstrate features of the API.
     * The code below query performs a time zone request for Github's server (San Francisco, California, United States). The timestamp is set to March 8th, 2012.
     *
     * @author Ivan Melgrati
     * @copyright 2018
     * @package GoogleMapsTimeZone
     * @author Ivan Melgrati
     * @version 1.5.0
     */

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

   
// Create GoogleMapsTimeZone object with default properties
   
$timezone_object = new GoogleMapsTimeZone();
   
   
// Set Google API key
   
$timezone_object->setApiKey(API_KEY);
   
   
// Set XML as query return format
   
$timezone_object->setFormat($timezone_object::FORMAT_XML);
   
   
// Set French as query return language
    // Check https://developers.google.com/maps/faq#languagesupport for a list of supported languages
   
$timezone_object->setLanguage('fr');
   
   
// Set latitude and longitude (New York City)
   
$timezone_object->setLatitude(40.730610)->setLongitude(-73.935242);
   
   
// Set Timestamp (server-side current time)
   
$timezone_object->setTimestamp(time());
   
   
// Perform query
   
$timezone_data = $timezone_object->queryTimeZone();

    echo
'<pre>';
   
print_r($timezone_data);
    echo
'</pre>';

   
   
// Set XML as query return format
   
$timezone_object->setFormat($timezone_object::FORMAT_JSON);
   
   
// Set Arabic as query return language
    // Check https://developers.google.com/maps/faq#languagesupport for a list of supported languages
   
$timezone_object->setLanguage('ar');
   
   
// Perform query
   
$timezone_data = $timezone_object->queryTimeZone();

    echo
'<pre>';
   
var_dump($timezone_data);
    echo
'</pre>';
?>


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

  Files folder image Files  /  docs  
File Role Description
Files folder imageclasses (2 files)
Files folder imagecss (5 files, 1 directory)
Files folder imagefiles (2 files)
Files folder imagefont (1 file)
Files folder imagegraphs (2 files)
Files folder imageimages (18 files, 1 directory)
Files folder imagejs (10 files, 1 directory)
Files folder imagenamespaces (3 files)
Files folder imagereports (3 files)
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Accessible without login HTML file index.html Doc. Documentation

  Files folder image Files  /  docs  /  classes  
File Role Description
  Accessible without login HTML file GoogleMapsTimeZone.html Doc. Documentation
  Accessible without login HTML file imelgrat.GoogleMap...leMapsTimeZone.html Doc. Documentation

  Files folder image Files  /  docs  /  css  
File Role Description
Files folder imagephpdocumentor-clean-icons (2 files, 1 directory)
  Accessible without login Plain text file bootstrap-combined.no-icons.min.css Data Auxiliary data
  Accessible without login Plain text file font-awesome.min.css Data Auxiliary data
  Accessible without login Plain text file jquery.iviewer.css Data Auxiliary data
  Accessible without login Plain text file prism.css Data Auxiliary data
  Accessible without login Plain text file template.css Data Auxiliary data

  Files folder image Files  /  docs  /  css  /  phpdocumentor-clean-icons  
File Role Description
Files folder imagefonts (2 files)
  Accessible without login Plain text file lte-ie7.js Data Auxiliary data
  Accessible without login Plain text file style.css Data Auxiliary data

  Files folder image Files  /  docs  /  css  /  phpdocumentor-clean-icons  /  fonts  
File Role Description
  Accessible without login Plain text file phpdocumentor-clean-icons.dev.svg Data Auxiliary data
  Accessible without login Plain text file phpdocumentor-clean-icons.svg Data Auxiliary data

  Files folder image Files  /  docs  /  files  
File Role Description
  Accessible without login HTML file GoogleMapsTimeZone.html Doc. Documentation
  Accessible without login Plain text file GoogleMapsTimeZone.php.txt Doc. Documentation

  Files folder image Files  /  docs  /  font  
File Role Description
  Accessible without login Plain text file fontawesome-webfont.svg Data Auxiliary data

  Files folder image Files  /  docs  /  graphs  
File Role Description
  Accessible without login HTML file class.html Doc. Documentation
  Accessible without login Plain text file classes.svg Data Auxiliary data

  Files folder image Files  /  docs  /  images  
File Role Description
Files folder imageiviewer (8 files)
  Accessible without login Image file android-chrome-192x192.png Icon Icon image
  Accessible without login Image file android-chrome-512x512.png Data Auxiliary data
  Accessible without login Image file apple-touch-icon-114x114.png Icon Icon image
  Accessible without login Image file apple-touch-icon-72x72.png Icon Icon image
  Accessible without login Image file apple-touch-icon.png Icon Icon image
  Accessible without login Plain text file custom-icons.svg Data Auxiliary data
  Accessible without login Image file favicon-16x16.png Icon Icon image
  Accessible without login Image file favicon-32x32.png Icon Icon image
  Accessible without login Image file favicon.ico Data Auxiliary data
  Accessible without login Image file hierarchy-item.png Icon Icon image
  Accessible without login Image file icon-class-13x13.png Icon Icon image
  Accessible without login Plain text file icon-class.svg Data Auxiliary data
  Accessible without login Image file icon-interface-13x13.png Icon Icon image
  Accessible without login Plain text file icon-interface.svg Data Auxiliary data
  Accessible without login Image file icon-trait-13x13.png Icon Icon image
  Accessible without login Plain text file icon-trait.svg Data Auxiliary data
  Accessible without login Image file mstile-150x150.png Icon Icon image
  Accessible without login Plain text file safari-pinned-tab.svg Data Auxiliary data

  Files folder image Files  /  docs  /  images  /  iviewer  
File Role Description
  Accessible without login Image file grab.cur Data Auxiliary data
  Accessible without login Image file hand.cur Data Auxiliary data
  Accessible without login Image file iviewer.rotate_left.png Icon Icon image
  Accessible without login Image file iviewer.rotate_right.png Icon Icon image
  Accessible without login Image file iviewer.zoom_fit.png Icon Icon image
  Accessible without login Image file iviewer.zoom_in.png Icon Icon image
  Accessible without login Image file iviewer.zoom_out.png Icon Icon image
  Accessible without login Image file iviewer.zoom_zero.png Icon Icon image

  Files folder image Files  /  docs  /  js  
File Role Description
Files folder imageui (1 directory)
  Accessible without login Plain text file bootstrap.min.js Data Auxiliary data
  Accessible without login Plain text file html5.js Data Auxiliary data
  Accessible without login Plain text file jquery-1.11.0.min.js Data Auxiliary data
  Accessible without login Plain text file jquery.dotdotdot-1.5.9.js Data Auxiliary data
  Accessible without login Plain text file jquery.dotdotdot-1.5.9.min.js Data Auxiliary data
  Accessible without login Plain text file jquery.iviewer.js Data Auxiliary data
  Accessible without login Plain text file jquery.iviewer.min.js Data Auxiliary data
  Accessible without login Plain text file jquery.mousewheel.js Data Auxiliary data
  Accessible without login Plain text file jquery.smooth-scroll.js Data Auxiliary data
  Accessible without login Plain text file prism.min.js Data Auxiliary data

  Files folder image Files  /  docs  /  js  /  ui  
File Role Description
Files folder image1.10.4 (1 file)

  Files folder image Files  /  docs  /  js  /  ui  /  1.10.4  
File Role Description
  Accessible without login Plain text file jquery-ui.min.js Data Auxiliary data

  Files folder image Files  /  docs  /  namespaces  
File Role Description
  Accessible without login HTML file default.html Doc. Documentation
  Accessible without login HTML file imelgrat.GoogleMapsTimeZone.html Doc. Documentation
  Accessible without login HTML file imelgrat.html Doc. Documentation

  Files folder image Files  /  docs  /  reports  
File Role Description
  Accessible without login HTML file deprecated.html Doc. Documentation
  Accessible without login HTML file errors.html Doc. Documentation
  Accessible without login HTML file markers.html Doc. Documentation

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file example-all-parameters.php Example Example script
  Accessible without login Plain text file example-basic.php Example Example script

  Files folder image Files  /  src  
File Role Description
  Plain text file GoogleMapsTimeZone.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:221
This week:0
All time:8,244
This week:132Up