0 Members and 1 Guest are viewing this topic.

AuthorTopic: Convert Exif 'GPSLatitude' และ 'GPSLongitude' เป็น lat, lng เพื่อ นำไปปักหมุดใน Google  (Read 1661 times)

Offline aegkaluk

  • Administrator
  • Hero Member
  • *****
  • Posts: 1103
  • Total Like : 0
    • Email
« on: 24, 10, 2011, 11:23:28 »
Code: [Select]
<?php
   $exif_data 
exif_read_data('images/photofromiphone.jpg');
        function 
defraction$fraction )
        {
            list( 
$nominator$denominator ) = explode"/"$fraction );

            if( 
$denominator )
            {
                return ( 
$nominator $denominator );
            }
            else
            {
                return 
$fraction;
            }
        }
        
// Get the exif data
        // Latitude
        
$northing = -1;
        if( 
$exif_data['GPSLatitudeRef'] && 'N' == $exif_data['GPSLatitudeRef'] )
        {
            
$northing 1;
        }

        
$northing *= defraction$exif_data['GPSLatitude'][0] ) + ( defraction($exif_data['GPSLatitude'][1] ) / 60 ) + ( defraction$exif_data['GPSLatitude'][2] ) / 3600 );

        
// Longitude
        
$easting = -1;
        if( 
$exif_data['GPSLongitudeRef'] && 'E' == $exif_data['GPSLongitudeRef'] )
        {
            
$easting 1;
        }

        
$easting *= defraction$exif_data['GPSLongitude'][0] ) + ( defraction$exif_data['GPSLongitude'][1] ) / 60 ) + ( defraction$exif_data['GPSLongitude'][2] ) / 3600 );
        
        echo
"<h1>lat :".$northing."</h1>";
        echo
"<h1>lng :".$easting."</h1>";
     
?>


ที่มา
http://stackoverflow.com/questions/2526304/php-extract-gps-exif-data
« Last Edit: 24, 10, 2011, 13:55:31 by aegkaluk »