Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Talk:Extract GPS coordinates from digital camera images using PHP

From Wiki
Jump to: navigation, search

Mikesparr - missing a step in geo coordinates

You need to edit your exif function to add the minus sign on lat/lon if S or W orientation respectively. I updated your code example with the fix below so it works "across the pond"...  ;-)


replace above function -----

function readGPSinfoEXIF($image_full_name) {

  $exif=exif_read_data($image_full_name, 0, true);
    if(!$exif || $exif['GPS']['GPSLatitude'] == ) {
      return false;
       } else {
       $lat_ref = $exif['GPS']['GPSLatitudeRef'];
       $lat = $exif['GPS']['GPSLatitude'];
       list($num, $dec) = explode('/', $lat[0]);
       $lat_s = $num / $dec;
       list($num, $dec) = explode('/', $lat[1]);
       $lat_m = $num / $dec;
       list($num, $dec) = explode('/', $lat[2]);
       $lat_v = $num / $dec;
       $lon_ref = $exif['GPS']['GPSLongitudeRef'];
       $lon = $exif['GPS']['GPSLongitude'];
       list($num, $dec) = explode('/', $lon[0]);
       $lon_s = $num / $dec;
       list($num, $dec) = explode('/', $lon[1]);
       $lon_m = $num / $dec;
       list($num, $dec) = explode('/', $lon[2]);
       $lon_v = $num / $dec;
       $lat_int = ($lat_s + $lat_m / 60.0 + $lat_v / 3600.0);
       // check orientaiton of latitude and prefix with (-) if S
       $lat_int = ($lat_ref == "S") ? '-' . $lat_int : $lat_int;
       $lon_int = ($lon_s + $lon_m / 60.0 + $lon_v / 3600.0);
       // check orientation of longitude and prefix with (-) if W
       $lon_int = ($lon_ref == "W") ? '-' . $lon_int : $lon_int;
       $gps_int = array($lat_int, $lon_int);
       return $gps_int;
       }
}

mikesparr 21:39, 28 January 2012 (EET)

Reema89 -

$dir = "./exif"; //$image="image.jpg";

function readGPSinfoEXIF($image_full_name) {

  $exif=exif_read_data($image_full_name, 0, true);
    if(!$exif || $exif['GPS']['GPSLatitude'] == ) {
      return false;

} else { $lat_ref = $exif['GPS']['GPSLatitudeRef']; $lat = $exif['GPS']['GPSLatitude']; list($num, $dec) = explode('/', $lat[0]); $lat_s = $num / $dec; list($num, $dec) = explode('/', $lat[1]); $lat_m = $num / $dec; list($num, $dec) = explode('/', $lat[2]); $lat_v = $num / $dec;

$lon_ref = $exif['GPS']['GPSLongitudeRef']; $lon = $exif['GPS']['GPSLongitude']; list($num, $dec) = explode('/', $lon[0]); $lon_s = $num / $dec; list($num, $dec) = explode('/', $lon[1]); $lon_m = $num / $dec; list($num, $dec) = explode('/', $lon[2]); $lon_v = $num / $dec;

$gps_int = array($lat_s + $lat_m / 60.0 + $lat_v / 3600.0, $lon_s

           + $lon_m / 60.0 + $lon_v / 3600.0);

return $gps_int; } }


        function dirImages($dir) 
        {
            $d = dir($dir); 
            while (false!== ($file = $d->read())) 
            {
            $extension = substr($file, strrpos($file, '.')); 
            if($extension == ".jpg" || $extension == ".jpeg" || $extension == ".gif"                                         
              |$extension == ".png") 

$images[$file] = $file; } $d->close(); return $images; } $array = dirImages('./exif'); $counter = 0;

foreach ($array as $key => $image) {

   echo "
";

$counter++;

   echo $counter;
   echo "
";

$image_full_name = $dir."/".$key; echo $image_full_name; $results = readGPSinfoEXIF($image_full_name); $latitude = $results[0]; echo $latitude;

           echo "
";

$longitude = $results[1]; echo $longitude;

   echo "
";

}

i used this php code i am getting warning Warning: dir(./exif,./exif) [function.dir]: The system cannot find the file specified. (code: 2) in C:\wamp\www\reema\self\exif\2.php on line 61

Warning: dir(./exif) [function.dir]: failed to open dir: No such file or directory in C:\wamp\www\reema\self\exif\2.php on line 61
Fatal error: Call to a member function read() on a non-object in C:\wamp\www\reema\self\exif\2.php on line 62

reema89 09:52, 18 February 2013 (EET)

 

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×