Get gps location of a photo

后端 未结 2 1776
南笙
南笙 2021-02-06 15:30

I know how to get the current GPS location of a mobile phone. I also know how to save the GPS location to the photo when you take it. (Camera option Samsung galaxy s2).

相关标签:
2条回答
  • 2021-02-06 15:40

    josnidhin made this answer possible, so be sure to give him credit too :)

    Here we go:

    import android.media.ExifInterface;
    
    exif = new ExifInterface(filePath);
    String lat = ExifInterface.TAG_GPS_LATITUDE;
    String lat_data = exif.getAttribute(lat);
    

    After that, lat_data will be something like: 51/1,58/1,32/1

    This is the same as: 51, 58, 32. (typing this in google maps will give bad result)

    To get the gps coordinates of this you need to do some math, here it comes:

    1. Calculate the total number of seconds:
      58′32″ = (58*60 + 32) = 3512 seconds.
    2. The fractional part is total number of seconds divided by 3600:
      3512 / 3600 = ~0.975556
    3. Add fractional degrees to whole degrees to produce the final result:
      51 + 0.975556 = 51.975556
    4. If it is a West longitude coordinate, negate the result. (it isn't this time)
    5. answer: 51.975556

    This is also the same when you with TAG_GPS_LONGITUDE

    0 讨论(0)
  • 2021-02-06 15:43

    I think the geotag is in the EXIF data of the photo taken. Find a suitable EXIF data reader which will help you extract the data you want.

    0 讨论(0)
提交回复
热议问题