Get the GPS address of the photo

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

But how can I get the GPS location of this photo (later)? When I open the photo on the computer, I can see the GPS location data, but I have no idea how to retrieve it later in Android. So can someone put me in a good direction? To clarify the question: How can I get the GPS location of an already taken photo?

Thanks, Bigflow

+3
source share
2 answers

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

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 look something like this: 51 / 1.58 / 1.32 / 1

This is the same as: 51, 58, 32. (typing this on google maps, you will get a bad result)

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

  • Calculate the total number of seconds:
    58'32 "= (58 * 60 + 32) = 3512 seconds.
  • The fractional part is the total number of seconds divided by 3600:
    3512/3600 = ~ 0.975556
  • Add fractional degrees to integer degrees to get the final result:
    51 + 0.975556 = 51.975556
  • If this is the west longitude coordinate, deny the result. (this is not this time)
  • answer: 51.975556

This is the same when you are with TAG_GPS_LONGITUDE

+18
source

I think the geotag is in the EXIF ​​photo data. Find the right EXIF ​​data reader to help you extract the data you need.

+9
source

Source: https://habr.com/ru/post/1416553/


All Articles