English 中文(简体)
GPS 坐标转换 - PHP
原标题:GPS Co-ordinate conversion - PHP
  • 时间:2012-05-26 21:31:45
  •  标签:
  • php
  • gps

我有以下代码从图像中提取和显示 EXIF 信息。

    <?
    // +++++++++++++++++++++++++ //
    // +++++++ 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页面上,请看http://ukf.com/siaexif/seaexif3.php

问题在于,返回的全球定位系统坐标在度/分/秒之间。

要将它们转换为十进制, 我有这个脚本 :

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

我需要的是十进制的逻辑和纬度

    $GPSDECLON
    $GPSDECLAT

这样我就可以把以上信息 放到我的 html 页面上。

我的PHP知识目前非常有限, 我不知道该如何将我现有的脚本转换成我现有的脚本。

有人能帮忙吗?

问题回答

网页上显示的秒数有些问题 -- -- 它们必须在范围[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秒的度数,有60秒的度数。如果你在南半球,你翻转纬度,如果你在“西半球”,你翻转经度值,这些只是两种测量的标志。

那么... So... So...

(美元GPSDegreeesLon, 美元GPSMinutesLon, 美元GPS secondsLon, 美元Hemisphere)

Where $EWHemisphere is "E" or "W" depending on how your hemisphere variable encodes it. Then it is a similar line for the latitude except you need to know if it is "N" or "S" for the sign.

希望那有帮助,我道歉 如果我错过了你的问题...





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签