Hello, fellow-androiders!
Recently I came across a problem where I needed to know where a given image was captured by using the location tagged in it. This comes with images taken in many cameras and smartphones that have the location tagging feature. I had to do this implementation for a native Android app, and so I did some research and found that the metadata is stored in a format abbreviated as Exif.
There is a support library called ExifInterface in Android that can be used to read and write EXIF tags in an image. In order to use this, you would have to provide the ExifInterface constructor with an InputStream of the image you want to extract metadata from.
This is the code that I used to extract the latitude and longitude of where the image was captured.
package com.wordpress.joelkingsley.imageproperties;
import android.support.media.ExifInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
InputStream in = getAssets().open("img.jpg");
ExifInterface exifInterface = new ExifInterface(in);
Log.d("Latitude", exifInterface.getAttribute(ExifInterface.TAG_GPS_LATITUDE));
Log.d("Longitude", exifInterface.getAttribute(ExifInterface.TAG_GPS_LONGITUDE));
} catch (IOException e) {
e.printStackTrace();
}
setContentView(R.layout.activity_main);
}
}
Make sure that the images that you take have GPS information including latitude and longitude when you right click and check the image properties in your computer or smartphone.

In this case, I had put the image in the assets folder of the app. You could, of course, do the same for images that are either stored in another server or is in the user’s internal or external storage. You will find answers in Stack Overflow on how to do that.
Feel free to ask if you have any questions in the comment section below.
Adios!