You are here

public function File::geocode in Geocoder 8.2

File

src/Geocoder/Provider/File.php, line 25

Class

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

Namespace

Drupal\geocoder\Geocoder\Provider

Code

public function geocode($filename) {

  // 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']) && $exif['GPSLongitude'] && $exif['GPSLongitudeRef']) {
      $latitude = $this
        ->getGpsExif($exif['GPSLatitude'], $exif['GPSLatitudeRef']);
      $longitude = $this
        ->getGpsExif($exif['GPSLongitude'], $exif['GPSLongitudeRef']);
      return $this
        ->returnResults([
        [
          'latitude' => $latitude,
          'longitude' => $longitude,
        ] + $this
          ->getDefaults(),
      ]);
    }
  }
  throw new NoResult(sprintf('Could not find geo data in file: "%s".', basename($filename)));
}