You are here

function geotimezone_query in Geo Time Zone 6

Same name and namespace in other branches
  1. 8.3 geotimezone.module \geotimezone_query()
  2. 8 geotimezone.module \geotimezone_query()
  3. 8.2 geotimezone.module \geotimezone_query()
  4. 6.2 geotimezone.module \geotimezone_query()
  5. 7.2 geotimezone.module \geotimezone_query()
  6. 7 geotimezone.module \geotimezone_query()

Query timezone based on coordinates.

Parameters

float $latitude: Latitude.

float $longitude: Longitude.

string $format: Desired return timezone format: 'name', 'offset' or 'both'

Return value

mixed Query result contains timezone name or offset or both.

File

./geotimezone.module, line 27
API that determines the timezone based on geo location (longitude/latitude). Using "geotimezone_query($latitude, $longitude, $format);" that returns timezone name or offset or bith (depends on $format value). This module does not need web…

Code

function geotimezone_query($latitude, $longitude, $format = 'both') {
  module_load_include('php', 'geotimezone', 'src/Timezone');
  module_load_include('php', 'geotimezone', 'src/TimezonePolygon');
  module_load_include('php', 'geotimezone', 'src/GeoTimezone');
  $geotimezone = new \Drupal\geotimezone\GeoTimezone($latitude, $longitude);
  if ($format == 'name') {
    return $geotimezone
      ->getName();
  }
  elseif ($format == 'offset') {
    return $geotimezone
      ->getOffset();
  }
  else {
    return [
      'name' => $geotimezone
        ->getName(),
      'offset' => $geotimezone
        ->getOffset(),
    ];
  }
}