如果图片存在“GPS”(纬度,经度)属性,我如何获取它们


How can i get the `GPS` (Latitude,longitude ) properties if they exist of a picture?

我想从桌面上的图片中获得纬度和经度信息。我非常在谷歌上搜索有关如何获取此信息的任何想法。我还在努力...如果有人对此有想法...那么请指导我..或尽可能提供任何解决方案。

首先要确保使用 EXif:

<?php
echo "test1.jpg:<br />'n";
$exif = exif_read_data('tests/test1.jpg', 'IFD0');
echo $exif===false ? "No header data found.<br />'n" : "Image contains headers<br />'n";
$exif = exif_read_data('tests/test2.jpg', 0, true);
echo "test2.jpg:<br />'n";
foreach ($exif as $key => $section) {
    foreach ($section as $name => $val) {
        echo "$key.$name: $val<br />'n";
    }
}
?>

然后

    <?php
$image_file = 'D:'Photoes'2011'IMG_0712.jpg';
if(file_exists($image_file)){
$details = exif_read_data($image_file);
$sections = explode(',',$details['SectionsFound']);
if(in_array('GPS',array_flip($sections))){
echo format_gps_data($details['GPSLatitude'],$details['GPSLatitudeRef']);
echo '<br/>';
echo format_gps_data($details['GPSLongitude'],$details['GPSLongitudeRef']);
}else{
die('GPS data not found');
}
}else{
die('File does not exists');
}
function format_gps_data($gpsdata,$lat_lon_ref){
$gps_info = array();
foreach($gpsdata as $gps){
list($j , $k) = explode('/', $gps);
array_push($gps_info,$j/$k);
}
$coordination = $gps_info[0] + ($gps_info[1]/60.00) + ($gps_info[2]/3600.00);
return (($lat_lon_ref == "S" || $lat_lon_ref == "W" ) ? '-'.$coordination : $coordination).' '.$lat_lon_ref;
}

?>

然后看看这个:与GPS信息合作得很好