php 通过exif_read_data读取GPS信息后计算出不正常的经纬度 20
照片是通过itools导出的,打印GPS数组array(14){["GPSLatitudeRef"]=>string(1)"N"["GPSLatitude"]=>arra...
照片是通过itools导出的,打印GPS数组array(14) {
["GPSLatitudeRef"] => string(1) "N"
["GPSLatitude"] => array(3) {
[0] => string(18) "637534208/16777216"
[1] => string(14) "922746880/-256"
[2] => string(5) "12/15"
}
["GPSLongitudeRef"] => string(1) "E"
["GPSLongitude"] => array(3) {
[0] => string(19) "2030043136/16777216"
[1] => string(14) "637534208/-256"
[2] => string(5) "12/15"
}
["GPSAltitudeRef"] => string(1) ""
["GPSAltitude"] => string(9) "43764/565"
["GPSTimeStamp"] => string(3) "3/1"
["GPSSpeedRef"] => string(1) "K"
["GPSSpeed"] => string(3) "0/1"
["GPSImgDirectionRef"] => string(1) "T"
["GPSImgDirection"] => string(9) "58427/235"
["GPSDestBearingRef"] => string(1) "T"
["GPSDestBearing"] => string(9) "58427/235"
["GPSDateStamp"] => string(10) "2018:04:25"
}
根据这个计算出来的 经纬度是经度:-41385.133111111 ,纬度-60036.666444444
这不是一个正常的经纬度,如何解决
计算方法如下:
function getGps($exifCoord,$banqiu) {
$sign = 1;
if(!isset($exifCoord) || $exifCoord=="")
return 0;
$degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0;
if($degrees<0)
$sign = -1;
$degrees = $degrees * $sign;
$minutes = count($exifCoord) > 1 ? gps2Num($exifCoord[1]) : 0;
$seconds = count($exifCoord) > 2 ? gps2Num($exifCoord[2]) : 0;
$minutes += 60 * ($degrees- floor($degrees));
$degrees = floor($degrees);
$seconds += 60 * ($minutes- floor($minutes));
$minutes = floor($minutes);
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);
}
$lng_lat = $degrees + $minutes/60 + $seconds/60/60;
$lng_lat = $lng_lat * $sign;
if(strtoupper($banqiu)=='W'||strtoupper($banqiu)=='S'){
$lng_lat = abs($lng_lat)*-1;
}
return $lng_lat;
}
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]);
} 展开
["GPSLatitudeRef"] => string(1) "N"
["GPSLatitude"] => array(3) {
[0] => string(18) "637534208/16777216"
[1] => string(14) "922746880/-256"
[2] => string(5) "12/15"
}
["GPSLongitudeRef"] => string(1) "E"
["GPSLongitude"] => array(3) {
[0] => string(19) "2030043136/16777216"
[1] => string(14) "637534208/-256"
[2] => string(5) "12/15"
}
["GPSAltitudeRef"] => string(1) ""
["GPSAltitude"] => string(9) "43764/565"
["GPSTimeStamp"] => string(3) "3/1"
["GPSSpeedRef"] => string(1) "K"
["GPSSpeed"] => string(3) "0/1"
["GPSImgDirectionRef"] => string(1) "T"
["GPSImgDirection"] => string(9) "58427/235"
["GPSDestBearingRef"] => string(1) "T"
["GPSDestBearing"] => string(9) "58427/235"
["GPSDateStamp"] => string(10) "2018:04:25"
}
根据这个计算出来的 经纬度是经度:-41385.133111111 ,纬度-60036.666444444
这不是一个正常的经纬度,如何解决
计算方法如下:
function getGps($exifCoord,$banqiu) {
$sign = 1;
if(!isset($exifCoord) || $exifCoord=="")
return 0;
$degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0;
if($degrees<0)
$sign = -1;
$degrees = $degrees * $sign;
$minutes = count($exifCoord) > 1 ? gps2Num($exifCoord[1]) : 0;
$seconds = count($exifCoord) > 2 ? gps2Num($exifCoord[2]) : 0;
$minutes += 60 * ($degrees- floor($degrees));
$degrees = floor($degrees);
$seconds += 60 * ($minutes- floor($minutes));
$minutes = floor($minutes);
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);
}
$lng_lat = $degrees + $minutes/60 + $seconds/60/60;
$lng_lat = $lng_lat * $sign;
if(strtoupper($banqiu)=='W'||strtoupper($banqiu)=='S'){
$lng_lat = abs($lng_lat)*-1;
}
return $lng_lat;
}
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]);
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询