You are here

public function File::geocodeQuery in Geocoder 8.3

File

modules/geocoder_field/src/Geocoder/Provider/File.php, line 32

Class

File
Provides a file handler to be used by 'file' plugin.

Namespace

Drupal\geocoder_field\Geocoder\Provider

Code

public function geocodeQuery(GeocodeQuery $query) : Collection {
  $filename = $query
    ->getText();

  // Check file type exists and is a JPG (IMAGETYPE_JPEG) before exif_read.
  if (file_exists($filename) && exif_imagetype($filename) == 2 && ($exif = @exif_read_data($filename))) {
    if (isset($exif['GPSLatitude']) && isset($exif['GPSLatitudeRef']) && isset($exif['GPSLongitude']) && $exif['GPSLongitudeRef']) {
      $latitude = $this
        ->getGpsExif($exif['GPSLatitude'], $exif['GPSLatitudeRef']);
      $longitude = $this
        ->getGpsExif($exif['GPSLongitude'], $exif['GPSLongitudeRef']);
      $result = Address::createFromArray([
        'providedBy' => $this
          ->getName(),
        'latitude' => $latitude,
        'longitude' => $longitude,
      ]);
      return new AddressCollection([
        $result,
      ]);
    }
  }
  throw new LogicException(sprintf('Could not find geo data in file: "%s".', basename($filename)));
}