Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8158391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:35:07+00:00 2026-06-06T17:35:07+00:00

I’ve searched everywhere for this but couldn’t find the solution, so I decided to

  • 0

I’ve searched everywhere for this but couldn’t find the solution, so I decided to write my own class for this in PHP. Some what I succeed in it with iPhone image file and instagram image but I am not sure if it works with all other cameras especially with Android supported phones and cameras with GPS. Can anyone help me out with this? Below is my code and its implementation.

    <?php

    class Filer {

        /**
         * Some Variables
         */

        private $_gpsLatitude;
        private $_gpsLongitude;
        private $_gpsLatitudeRef;
        private $_gpsLongitudeRef;

        /**
         * Constructor Method
         */
        public function __construct(){
            /**
             * GPS Meta (In reference to iphone's image file)
             * May be Android folow the same thing (Haven't checked)
             */
            $this->_gpsLatitude = 'GPSLatitude';
            $this->_gpsLongitude = 'GPSLongitude';
            $this->_GPSLongitudeRef = 'GPSLatitudeRef';
            $this->_gpsLongitudeRef = 'GPSLongitudeRef';
        }

        /**
         * Check if the file contains GPS information
         * @param: (string)$_file
         * @return: (array) File's EXIF data (If the file contains GPS information)
         */

        public function getCoordinate($_file){
            $_Metas = $this->checkGPS($_file);
            $_GPS = $_Metas['GPS'];
            $_latitude = $this->DMStoDEC(
                $_GPS[$this->_gpsLatitude][0], 
                $_GPS[$this->_gpsLatitude][1], 
                $_GPS[$this->_gpsLatitude][2], 
                $_GPS[$this->_GPSLongitudeRef]
            );
            $_longitude = $this->DMStoDEC(
                $_GPS[$this->_gpsLongitude][0], 
                $_GPS[$this->_gpsLongitude][1], 
                $_GPS[$this->_gpsLongitude][2], 
                $_GPS[$this->_gpsLongitudeRef]
            );

            $_location = array($_latitude, $_longitude);
            return $_location;
        }

        /**
         * Check if the file contains GPS information
         * @param: (string)$_file
         * @return: (array) File's EXIF data (If the file contains GPS information)
         */
        public function checkGPS($_file){
            return exif_read_data($_file, 'GPS', true);
        }

        /**
         * Get Meta information of file
         * @param: (string)$_file
         * @return: (array) File's EXIF data
         * 
         */
        public function getExif($_file){
            return exif_read_data($_file, 'IFD0', true);
        }

        /**
         * Converts DMS ( Degrees / Minutes / Seconds )
         * To decimal format longitude / latitude
         * @param: (string)$_deg, (string)$_min, (string)$_sec, (string)$_ref
         * @return: (float)
         */
        private function DMStoDEC($_deg, $_min, $_sec, $_ref){

            $_array = explode('/', $_deg);
            $_deg = $_array[0]/$_array[1];
            $_array = explode('/', $_min);
            $_min = $_array[0]/$_array[1];
            $_array = explode('/', $_sec);
            $_sec = $_array[0]/$_array[1];

            $_coordinate = $_deg+((($_min*60)+($_sec))/3600);
            /**
             *  + + = North/East
             *  + - = North/West
             *  - - = South/West
             *  - + = South/East        
            */
            if('s' === strtolower($_ref) || 'w' === strtolower($_ref)){
                // Negatify the coordinate
                $_coordinate = 0-$_coordinate;
            }

            return $_coordinate;
        }    

        /**
         * 
         * Converts decimal longitude / latitude to DMS
         * ( Degrees / minutes / seconds ) 
         *
         * This is the piece of code which may appear to 
         * be inefficient, but to avoid issues with floating
         * point math we extract the integer part and the float
         * part by using a string function.
         * @param: (string)$_file
         * @return: (array)
         */
        private function DECtoDMS($_dec){
            $_vars = explode(".", $_dec);
            $_deg = $vars[0];
            $_tempma = "0.".$_vars[1];

            $_tempma = $_tempma * 3600;
            $_min = floor($_tempma / 60);
            $_sec = $_tempma - ($_min*60);

            return array("deg"=>$_deg, "min"=>$_min, "sec"=>$_sec);
        }

    } // End class

    /**
     *
     * Usage Example
     * 
     */
    $_file = './image2.jpg';
    $_Filer = new Filer();
    if($_Filer->checkGPS($_file)){
        $_location = $_Filer->getCoordinate($_file);
        // File doesn't have GPS information
        echo '<h4>File\'s GPS information</h4>';
        var_dump($_location);
    } else {
        // File doesn't have GPS information
        echo '<h4>Sorry your file doesn\'t supply GPS information</h4>';
        var_dump($_Filer->getExif($_file));
    }
?>  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:35:08+00:00Added an answer on June 6, 2026 at 5:35 pm

    The Exiv2 documentation has an excellent tags reference which may help you identify fields you may have missed. Your implementation otherwise looks pretty solid to me, I can’t see any glaring errors.

    Exif Tags supported by Exiv2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.