You are here

public function IpGeoLocGlobal::reverseGeocodeTimeout in IP Geolocation Views & Maps 8

Handle timeout of the Google Maps reverse-geocode callback, if enabled.

This is based on $position_pending_since being set to the current time when the service was initiated.

File

src/Services/IpGeoLocGlobal.php, line 228

Class

IpGeoLocGlobal
Class IpGeoLocGlobal.

Namespace

Drupal\ip_geoloc\Services

Code

public function reverseGeocodeTimeout() {
  $pending_since = $this->ipGeolocSession
    ->getSessionValue('position_pending_since');
  if (isset($pending_since)) {
    $time_elapsed = microtime(TRUE) - $pending_since;
    if ($time_elapsed > IP_GEOLOC_CALLBACK_TIMEOUT) {
      $this
        ->debug($this->stringTranslation
        ->translate('IPGV&M timeout: the last reverse-geocode request was @sec s ago.', [
        '@sec' => number_format($time_elapsed, 1),
      ]));
      $this->ipGeolocSession
        ->setSessionValue('position_pending_since', NULL);
      return $time_elapsed;
    }
  }
  return FALSE;
}