gpt4 book ai didi

PHP提取GPS EXIF数据

转载 作者:IT王子 更新时间:2023-10-28 23:56:34 26 4
gpt4 key购买 nike

我想使用 php 从图片中提取 GPS EXIF 标签。我正在使用 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 以在 map 上显示图片位置!

最佳答案

这是我的修改版。其他的对我不起作用。它将为您提供 GPS 坐标的十进制版本。

处理EXIF数据的代码:

$exif = exif_read_data($filename);
$lon = getGps($exif["GPSLongitude"], $exif['GPSLongitudeRef']);
$lat = getGps($exif["GPSLatitude"], $exif['GPSLatitudeRef']);
var_dump($lat, $lon);

以这种格式打印出来:

float(-33.8751666667)
float(151.207166667)

以下是函数:

function getGps($exifCoord, $hemi) {

$degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0;
$minutes = count($exifCoord) > 1 ? gps2Num($exifCoord[1]) : 0;
$seconds = count($exifCoord) > 2 ? gps2Num($exifCoord[2]) : 0;

$flip = ($hemi == 'W' or $hemi == 'S') ? -1 : 1;

return $flip * ($degrees + $minutes / 60 + $seconds / 3600);

}

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]);
}

关于PHP提取GPS EXIF数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2526304/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com