Reputation: 729
I am trying to retrieve latitude and longitude information of an image. Here is the code I have:
String[] columns = { MediaStore.Images.ImageColumns.LATITUDE,
MediaStore.Images.ImageColumns.LONGITUDE,
MediaStore.Images.ImageColumns.TITLE,
MediaStore.Images.ImageColumns.DATA,
MediaStore.Images.ImageColumns.DATE_TAKEN
};
final String orderBy = MediaStore.Images.ImageColumns.DATE_MODIFIED + " DESC";
Cursor cursor = activity.managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
columns,
null,
null,
orderBy
);
int count = cursor.getCount();
Double latitude, longitude;
String filePath;
for (int i = 0; i < count; i++) {
cursor.moveToPosition(i);
latitude = cursor.getDouble(cursor.getColumnIndex(MediaStore.Images.ImageColumns.LATITUDE));
longitude = cursor.getDouble(cursor.getColumnIndex(MediaStore.Images.ImageColumns.LONGITUDE));
filePath = cursor.getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA));
Log.i("Image>>",filePath);
Log.i("Latitude>>", latitude+"");
Log.i("Longitude>>",longitude+"");
}
But latitude and longitude are always 0.0. I am using Android SDK 16. Can you please help? Thanks in advance.
Upvotes: 0
Views: 899
Reputation: 729
My bad. I enabled location on camera before taking a snap and this returns the correct location.!
Upvotes: 2