Skip to content

Geo Loacation

PHP
  • 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/

  • PHP - ChatGPT

    PHP
    1
    0 Votes
    1 Posts
    64 Views
    No one has replied
  • 0 Votes
    1 Posts
    39 Views
    No one has replied
  • PHP Installation

    Pinned PHP
    3
    0 Votes
    3 Posts
    518 Views
    FrankMF

    Falls jemand auch die Warnung in Joomla! bezüglich der php Version 7.4 loswerden möchte, installiert kein php8.1. Damit habe ich eine dicke Fehlermeldung. Es müssen wohl sämtliche Erweiterungen und Templates 8.1 unterstützen, was wohl derzeit noch nicht der Fall ist. Nehmt 8.0, das läuft bei mir aktuell.

    apt install php8.0-common php8.0-mysql php8.0-opcache php8.0-readline php8.0-xml php8.0-xsl php8.0-zip apt install php8.0-cli php8.0-curl php8.0-gd php8.0-intl php8.0-mbstring php8.0-redis apt install php8.0-bcmath php8.0-gmp php8.0-imagick apt install php8.0-fpm
  • Wichtige Info

    Pinned PHP
    1
    0 Votes
    1 Posts
    195 Views
    No one has replied
  • PHPMailer

    Moved PHP
    1
    0 Votes
    1 Posts
    414 Views
    No one has replied
  • Wichtige Links zum Coden

    PHP
    1
    0 Votes
    1 Posts
    356 Views
    No one has replied
  • Reload einer PHP Seite verhindern

    PHP
    1
    0 Votes
    1 Posts
    688 Views
    No one has replied
  • PHP Exif Daten aus Bild auslesen

    Moved PHP
    1
    0 Votes
    1 Posts
    460 Views
    No one has replied