Geo Loacation



  • In den exif Daten können sich die GPS Daten des Standortes verstecken. Die wollen wir haben 😉

     <?php
       
      //Test ob in der Datei GPS Daten drin sind   
      $img = '../upload/IMG_20181117_104123_ergebnis_34.jpg'; //or $fileName='xxxxxxxxx';
      $test = exif_read_data($img, 0, true);
      var_dump($test);
     
     echo "<br>";
     echo "<br>";
     
      $img = '../upload/IMG_20181206_153916.jpg'; //or $fileName='xxxxxxxxx';
      $test = exif_read_data($img, 0, true);
      var_dump($test);
     
           
      /**
      * get_image_location
      * Returns an array of latitude and longitude from the Image file
      * @param $image file path
      * @return multitype:array|boolean
      */
     function get_image_location($image = ''){
         $exif = exif_read_data($image, 0, true);
         if($exif && isset($exif['GPS'])){
             $GPSLatitudeRef = $exif['GPS']['GPSLatitudeRef'];
             $GPSLatitude    = $exif['GPS']['GPSLatitude'];
             $GPSLongitudeRef= $exif['GPS']['GPSLongitudeRef'];
             $GPSLongitude   = $exif['GPS']['GPSLongitude'];
             
             $lat_degrees = count($GPSLatitude) > 0 ? gps2Num($GPSLatitude[0]) : 0;
             $lat_minutes = count($GPSLatitude) > 1 ? gps2Num($GPSLatitude[1]) : 0;
             $lat_seconds = count($GPSLatitude) > 2 ? gps2Num($GPSLatitude[2]) : 0;
             
             $lon_degrees = count($GPSLongitude) > 0 ? gps2Num($GPSLongitude[0]) : 0;
             $lon_minutes = count($GPSLongitude) > 1 ? gps2Num($GPSLongitude[1]) : 0;
             $lon_seconds = count($GPSLongitude) > 2 ? gps2Num($GPSLongitude[2]) : 0;
             
             $lat_direction = ($GPSLatitudeRef == 'W' or $GPSLatitudeRef == 'S') ? -1 : 1;
             $lon_direction = ($GPSLongitudeRef == 'W' or $GPSLongitudeRef == 'S') ? -1 : 1;
             
             $latitude = $lat_direction * ($lat_degrees + ($lat_minutes / 60) + ($lat_seconds / (60*60)));
             $longitude = $lon_direction * ($lon_degrees + ($lon_minutes / 60) + ($lon_seconds / (60*60)));
     
             return array('latitude'=>$latitude, 'longitude'=>$longitude);
         }else{
             return false;
         }
     }
     
     function gps2Num($coordPart){
         $parts = explode('/', $coordPart);
         if(count($parts) <= 0)
         return 0;
         if(count($parts) == 1)
         return $parts[0];
         return floatval($parts[0]) / floatval($parts[1]);
     }
     
     
     $imageURL = "../upload/IMG_20181117_104123_ergebnis_34.jpg";
     //$imageURL = "../upload/IMG_20181201_081430.jpg";
     
     //get location of image
     $imgLocation = get_image_location($imageURL);
     var_dump($imgLocation);
    
    //Fehlerbehandlung
     if ($imgLocation == false) {
         echo "ERROR";
     }
    
     //Ausgabe
     //latitude & longitude
     $imgLat = $imgLocation['latitude'];
     $imgLng = $imgLocation['longitude'];
     echo "<br>";
     echo $imgLat . "<br>";
     echo $imgLng;
    

    Muss noch optimiert werden!

    Quelle: https://www.codexworld.com/get-geolocation-latitude-longitude-from-image-php/


 

Diese Artikel könnten Dich auch interessieren.