How to get EXIF tags (GPS Coordinates, Time, Date) from a picture

A few days ago I released a new Android app on the Android Market. The app maps the last 500 photos (500 due to performance)  from the default camera folder. I been meaning to build it for awhile but adding a Android Map can be  a pain. Check out the screen shot.


I do not expect this to be a game changer but if it seems to have potential then I will add features. With that said I am going to speak on how to get GPS coordinates and the date/time of a picture. Good thing is that when you get the EXIF from a photo than you get any tag/attribute you like.

Here is the code. Leave me a comment if I need to clear up anything

public Picture getpicturdata(){

		File sd = new File (Environment.getExternalStoragePublicDirectory(
		            Environment.DIRECTORY_DCIM) , "/Camera/xxxx.jpg"); // get file from the default camera folder

		ExifInterface exif = new ExifInterface(sd.toString()); // create the ExifInterface file

     /** get the attribute. rest of the attributes are the same. i will add convertToDegree on the bottom (not required) **/
		float log = convertToDegree(exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE));

		if(!exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF).equals("E"))	{ // deal with the negative degrees
			log = -log;	
		float lat = convertToDegree(exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE));
		if(!exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF).equals("N"))	{
			lat = -lat;
                 /** Create a class. Will add tempplate on the bottom**/
		Picture temp = new pictureData(log, lat,exif.getAttribute(ExifInterface.TAG_GPS_DATESTAMP) ,exif.getAttribute(ExifInterface.TAG_GPS_TIMESTAMP));

		return temp;

ConvertToDegree method (thanks to the person on StackOverFlow):

 private Float convertToDegree(String stringDMS){
	    	 Float result = null;
	    	 String[] DMS = stringDMS.split(",", 3);

	    	 String[] stringD = DMS[0].split("/", 2);
	    	    Double D0 = new Double(stringD[0]);
	    	    Double D1 = new Double(stringD[1]);
	    	    Double FloatD = D0/D1;

	    	 String[] stringM = DMS[1].split("/", 2);
	    	 Double M0 = new Double(stringM[0]);
	    	 Double M1 = new Double(stringM[1]);
	    	 Double FloatM = M0/M1;

	    	 String[] stringS = DMS[2].split("/", 2);
	    	 Double S0 = new Double(stringS[0]);
	    	 Double S1 = new Double(stringS[1]);
	    	 Double FloatS = S0/S1;

	    	    result = new Float(FloatD + (FloatM/60) + (FloatS/3600));

	    	 return result;


Picture Class  


public class Picture {
	float lat;
	float log;
	String date;
	String time;

    Picture(float lat, float log , String date, String time,  String path){ =lat;
	   this.log =log; = date;
	   this.time = time;

Posted by in Coding


Permalink 1 Comment

  • Ranjan

    Hey thanks ,
    Was of lot of help

Graveyard Database Logo

Has everything you want to know about grave yards. Plus has many celebrites and world leaders graves. Pssst it is my other site

Google + Profile
Check out Android Photo Mapping, its a app/site I been working on

  • wholesale sports jerseys
  • Fabulou wholesale Petr Mrazek jersey is back. Best choice to get the wholesale Petr Mrazek jersey is suitable for all style of people.