我想使用php从图片中提取GPS EXIF标签。我正在使用exif_read_data()返回所有标签+数据的数组的:
exif_read_data()
GPS.GPSLatitudeRef: N GPS.GPSLatitude:Array ( [0] => 46/1 [1] => 5403/100 [2] => 0/1 ) GPS.GPSLongitudeRef: E GPS.GPSLongitude:Array ( [0] => 7/1 [1] => 880/100 [2] => 0/1 ) GPS.GPSAltitudeRef: GPS.GPSAltitude: 634/1
我不知道如何解释46/1 5403/100和0/1?46可能是46°,但是其余的尤其是0/1呢?
angle/1 5403/100 0/1
这个结构是关于什么的?
如何将它们转换为“标准”(例如,维基百科的46°56′48″ N 7°26′39″ E)?我想将这些坐标传递给Google Maps API,以在地图上显示图片位置!
根据http://en.wikipedia.org/wiki/Geotagging,( [0] => 46/1 [1] => 5403/100 [2] => 0/1 )应表示46/1度,5403/100分钟,0/1秒,即46°54.03′0″ N。对秒进行归一化得到46°54′1.8″ N。
( [0] => 46/1 [1] => 5403/100 [2] => 0/1 )
只要您没有得到负坐标(只要您将N / S和E / W作为单独的坐标,就永远不要有负坐标),下面的代码就可以工作。让我知道是否存在错误(目前没有方便的PHP环境)。
//Pass in GPS.GPSLatitude or GPS.GPSLongitude or something in that format function getGps($exifCoord) { $degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0; $minutes = count($exifCoord) > 1 ? gps2Num($exifCoord[1]) : 0; $seconds = count($exifCoord) > 2 ? gps2Num($exifCoord[2]) : 0; //normalize $minutes += 60 * ($degrees - floor($degrees)); $degrees = floor($degrees); $seconds += 60 * ($minutes - floor($minutes)); $minutes = floor($minutes); //extra normalization, probably not necessary unless you get weird data if($seconds >= 60) { $minutes += floor($seconds/60.0); $seconds -= 60*floor($seconds/60.0); } if($minutes >= 60) { $degrees += floor($minutes/60.0); $minutes -= 60*floor($minutes/60.0); } return array('degrees' => $degrees, 'minutes' => $minutes, 'seconds' => $seconds); } function gps2Num($coordPart) { $parts = explode('/', $coordPart); if(count($parts) <= 0)// jic return 0; if(count($parts) == 1) return $parts[0]; return floatval($parts[0]) / floatval($parts[1]); }