2012-05-26 5 views
0

다음 코드를 사용하여 이미지에서 EXIF ​​정보를 추출하고 표시 할 수 있습니다. 문제는 반환 된 GPS 좌표가 학위에/분/초는 것을 여기 http://ukf.com/easyexif/easyexif3.phpGPS 좌표 변환 - PHP

볼 수 있듯이

<? 
    // +++++++++++++++++++++++++ // 
    // +++++++ GPS EXIF +++++++ // 
    // +++++++++++++++++++++++++ // 

    // --- Change the 'image1.jpg' value below to the path of your file. --- // 
    $Image = 'image1.jpg'; 

    // --- The EXIF read command --- // 
    $ReadEXIFData = read_exif_data($Image, 0, true); 


    // +++++++++++++++++ // 
    // +++ FILE INFO +++ // 
    // +++++++++++++++++ // 
    // --- Get the filename --- // 
    $Filename = $ReadEXIFData['FILE']['FileName']; 
    // --- Get the file size --- // 
    $FileSize = $ReadEXIFData['FILE']['FileSize']; 
    // --- Converts to user-friendly kb, mb and gb sizes --- // 
    if ($FileSize >= 1024) { $ImageFileSize = number_format($FileSize/1024, 2).'kb'; } 
    elseif ($FileSize >= 1048576) { $ImageFileSize = number_format($FileSize/1048576, 2).'mb'; } 
    elseif ($FileSize >= 1073741824) { $ImageFileSize = number_format($FileSize/1073741824, 2).'gb'; } 
    // --- Get the file height --- // 
    $FileHeight = $ReadEXIFData['COMPUTED']['Height'].'px'; 
    // --- Get the file height --- // 
    $FileWidth = $ReadEXIFData['COMPUTED']['Width'].'px'; 



    // +++++++++++++++++++++++ // 
    // +++ GPS COORDINATES +++ // 
    // +++++++++++++++++++++++ // 
    // --- Get GPS hemisphire --- // 
    $GPSHemisphire = $ReadEXIFData["GPS"]["GPSLatitudeRef"]; 

    // --- Get GPS degrees latitude --- // 
    $GPSDegreesLat = intval($ReadEXIFData["GPS"]["GPSLatitude"][0]); 
    // --- Get GPS minutes latitude --- // 
    $GPSMinutesLat = intval($ReadEXIFData["GPS"]["GPSLatitude"][1]); 
    // --- Get GPS seconds latitude --- // 
    $GPSSecondsLat = intval($ReadEXIFData["GPS"]["GPSLatitude"][2]); 
    // --- Get GPS Hemisphere latitude --- // 
    $GPSSecondsLat2 = ($ReadEXIFData["GPS"]["GPSLatitudeRef"]); 
    // --- Decimal Latitude goes here --- // 


    // --- Get GPS degrees longitude --- // 
    $GPSDegreesLon = intval($ReadEXIFData["GPS"]["GPSLongitude"][0]); 
    // --- Get GPS minutes longitude --- // 
    $GPSMinutesLon = intval($ReadEXIFData["GPS"]["GPSLongitude"][1]); 
    // --- Get GPS seconds longitude --- // 
    $GPSSecondsLon = intval($ReadEXIFData["GPS"]["GPSLongitude"][2]); 
    // --- Get GPS Hemisphere longitude --- // 
    $GPSSecondsLon2 = ($ReadEXIFData["GPS"]["GPSLongitudeRef"]); 
    // --- Decimal Longitude goes here --- // 


    // --- Get GPS altitude --- // 
    $GPSAltitude = $ReadEXIFData["GPS"]["GPSAltitude"][0]; 


    ?> 

정보

는 HTML 페이지에 인쇄됩니다.

$GPSDECLON 
    $GPSDECLAT 

그래서 위의 정보를 포함 할 수

function toDecimal($deg, $min, $sec, $hemi) { 
    $d = $deg + $min/60 + $sec/3600; 
    return ($hemi=='S' || $hemi=='W') ? $d*=-1 : $d; 
    } 

    function divide($a) { 
    $e = explode('/', $a); 
    if (!$e[0] || !$e[1]) { 
     return 0; 
    } else { 
     return $e[0]/$e[1]; 
    } 
    } 

    function getGPS() { 
    global $exif; 
    if ($exif) { $lat = $exif['GPS']['GPSLatitude']; 
    $log = $exif['GPS']['GPSLongitude']; 
     if (!$lat || !$log) return null; 
     $lat_degrees = divide($lat[0]); 
     $lat_minutes = divide($lat[1]); 
     $lat_seconds = divide($lat[2]); 
     $lat_hemi = $exif['GPS']['GPSLatitudeRef']; 
     $log_degrees = divide($log[0]); 
     $log_minutes = divide($log[1]); 
     $log_seconds = divide($log[2]); 
     $log_hemi = $exif['GPS']['GPSLongitudeRef']; 
     $lat_decimal = toDecimal($lat_degrees, $lat_minutes, $lat_seconds, $lat_hemi); 
     $log_decimal = toDecimal($log_degrees, $log_minutes, $log_seconds, $log_hemi); 
     return array($lat_decimal, $log_decimal); 
    } else{ 
     return null; 
    } 
    } 

는 내가 필요로하는 소수 Logitude와 위도 형태로 반환됩니다

것은 나는이 스크립트가 진수로 변환하려면 내 HTML 페이지에서.

내 PHP 지식이 현재 너무 제한되어 있습니다. 기존 스크립트로 변환하는 방법을 포함하여 어떻게해야하는지 잘 모릅니다.

아무도 도와 줄 수 있습니까 ?? 그렇다면 크게 평가 받게 될 것입니다. 초는 웹 페이지에 표시와 함께

+0

은 내가 $ GPSSecondsLat2'와'$ GPSSecondsLon2' 당신이 단지 무엇을 할 수있다 '추측 것이 스크립트에 신선한 제공된 경우 위도와 경도를 10 진수 초로 표시합니다. 제쳐두고, $ GPSHemisphire에 대한 할당이 올바르지 않은 것 같습니다. – SEngstrom

+0

죄송합니다 - 언급 된 'Decimal Latitude goes here'및 'Decimal Longitude goes here'는 변환 스크립트가 추가 될 때 계산할 새 값의 표제입니다. $ GPSSecondsLat2와 $ GPSSecondsLon2는 Hemisphere 값 (예 : N/S 및 E/W)을 호출하면 웹 페이지에서 모양을 나타내며 의미를 알 수 있습니다. – pewe

답변

0

뭔가 어긋입니다 - 그들은 범위 [말했다 0,60 [

에 있어야, 변환은 PHP 코드의 첫 번째 기능에 말하는 당신 게시 :

function toDecimal($deg, $min, $sec, $hemi) { 
$d = $deg + $min/60 + $sec/3600; 
return ($hemi=='S' || $hemi=='W') ? $d*=-1 : $d; 
} 

즉, 60 분에서 60 초까지입니다. 남반구에 있다면 위도를 뒤집습니다. "서반구"에 있다면 경도 값을 뒤집을 수 있습니다. 이것은 기본적으로 두 측정 값의 부호입니다.

그래서 ...

$ GPSDECLON = toDecimal ($ GPSDegreesLon, $ GPSMinutesLon, $ GPSSecondsLon, $ EWHemisphere)

$ EWHemisphere이 방법 반구 변수에 따라 "E"또는 "W"이다

그것을 인코딩합니다. 그런 다음 기호에 대해 "N"또는 "S"인지 알아야 할 위치를 제외하고는 위도와 비슷한 선입니다. 도움이 내가 여기에 질문을 누락하면 내가 사과

희망은 ...

+0

원래 스크립트 (intval)에 코드 조각이있어서 그 값을 제거하여 그 일부를 제거했습니다. 그것이 당신이 그들을 보았을 때 가치가 나타나는 이유입니다. 'intval'을 제거 했으므로 웹 페이지에서 값이 분수로 반환됨을 알 수 있습니다. 제가 게시 한 코드의 목적은 분수를 분리하고 분수를 반환하여 십진수 인 값을 반환하고 miutes 및 초를 소수의 소수로 변환하는 것입니다. 결과는 예를 들어 위도에 대해 51.48571236이어야합니다. 코드가 작동하지만 원본 스크립트에 삽입하는 방법을 모르겠습니다. – pewe