Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to extract gps location of user input image and then mark it on the map. but here in this javascript it is not showing correct result of gps data in console when i converting it into decimals (latitude and longitude)

What I have tried:

JavaScript
function readURL(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();

            reader.onload = function (e) {
                $('#the-img')
                    .attr('src', e.target.result)
                    .width(150)
                    .height(200);
            };

            reader.readAsDataURL(input.files[0]);
        }
    }

    document.getElementById("the-img").onclick = function() {

        EXIF.getData(this, function() {

            myData = this;

            console.log(myData.exifdata);

            var latDegree = myData.exifdata.GPSLatitude[0].numerator;
            var latMinute = myData.exifdata.GPSLatitude[1].numerator;
            var latSecond = myData.exifdata.GPSLatitude[2].numerator;
            var latDirection = myData.exifdata.GPSLatitudeRef;

            var latFinal = ConvertDMSToDD(latDegree, latMinute, latSecond, latDirection);
            console.log(latFinal);

// Calculate longitude decimal
            var lonDegree = myData.exifdata.GPSLongitude[0].numerator;
            var lonMinute = myData.exifdata.GPSLongitude[1].numerator;
            var lonSecond = myData.exifdata.GPSLongitude[2].numerator;
            var lonDirection = myData.exifdata.GPSLongitudeRef;

            var lonFinal = ConvertDMSToDD(lonDegree, lonMinute, lonSecond, lonDirection);
            console.log(lonFinal);
        });
      }

      function ConvertDMSToDD(degrees, minutes, seconds, direction) {

          var dd = degrees + (minutes/60) + (seconds/3600);

          if (direction == "S" || direction == "W") {
              dd = dd * -1;
          }

          return dd;
      }
Posted
Comments
[no name] 23-Jun-19 9:37am    
You should add some example data and show what you get and what you expect.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900