コード例 #1
0
 public function timezoneFromCoords($lat, $long, $time)
 {
     $default = "UTC";
     $tz = null;
     if ($this->timezone) {
         return $this->timezone;
     }
     if (isset(self::$previousPoint) && abs($this->distance(self::$previousPoint->lat, self::$previousPoint->long, $lat, $long)) < 50000) {
         //previous TZ was less than 50km from here.  Use same timezone.  Needed as google is taking >3s to return TZ.
         return self::$previousPoint->tz;
     }
     if (!isset($this->googleMaps) || !$this->googleMaps) {
         return $default;
     }
     if (!$time) {
         $time = $this->start_day;
     }
     $tz = $this->googleMaps->timezoneFromCoords($lat, $long, $time);
     if (!$tz) {
         $error = $this->googleMaps->getError();
         $this->error .= $error;
     }
     if (!$tz) {
         if (isset(self::$previousPoint)) {
             $tz = self::$previousPoint->tz;
         } else {
             $tz = $default;
         }
         $this->output("<br>Unable to find timezone for ride on {$this->current_day}, defaulting to {$tz}.<br>");
     } else {
         self::$previousPoint = new stdClass();
         self::$previousPoint->lat = $lat;
         self::$previousPoint->long = $long;
         self::$previousPoint->tz = $tz;
     }
     return $tz;
 }