Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the location data of a video in Android?

I am trying to get the metadata for the video files stored on my app's user's phone. I can get the file name, id, date taken and so on. However, latitude and longitude data always returns as 0.0. I have been referring to this:

developer.android.com/reference/android/provider/MediaStore.Video.VideoColumns.html

Yes, I am already enabling use location in my settings. I have a very similar function to this for images which works fine.

public void getLocalVideoFiles(Context context) {
    ContentResolver videoResolver = context.getContentResolver();
    Uri videoUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
    String test = getRealPathFromURI(context, videoUri);
    Cursor videoCursor = videoResolver.query(videoUri, null, null, null, null);

    if(videoCursor!=null && videoCursor.moveToFirst()){
        //get columns
        int latColumn = videoCursor.getColumnIndex
                (MediaStore.Video.Media.LATITUDE);
        int lonColumn = videoCursor.getColumnIndex
                (MediaStore.Video.Media.LONGITUDE);

        do {
            String thisLat = Double.toString(videoCursor.getDouble(latColumn));
            String thisLon = Double.toString(videoCursor.getDouble(lonColumn));

            Log.d("video Latitude",thisLat);
            Log.d("video Longitude",thisLon);
        }
        while (videoCursor.moveToNext());
    }
    return localClips;
}

The approach described here: Geotagging a captured video yields similar results (null value in the METADATA_KEY_LOCATION column).

So, my question is: does the built-in Android video tool record location data when creating videos? It seems like the answer is no, but I don't understand why there are columns for the location data if this is the case. If that is not the case, how can I access the video location data? I need the location of video files that have already been taken.

Thanks in advance!

like image 973
fullmeriffic Avatar asked Oct 31 '22 07:10

fullmeriffic


1 Answers

Well i've just tested your assumption that google does not keep location data while recording video and it's incorrect.

For example: using my nexus 5 with version 5.1 i was able to get a geotag on a video i just took. you can try it by yourself and if your phone is rooted, just browse the MediaStore external DB (com.android.providers.media) using some SQLITE viewer

but let's say that google does not keep GeoTag. there are number of reasons why they would keep such a column:

  • To support other video libraries that do want to keep geo taggging
  • To allow users who are implementing Video recorder a way to save current location ( using FusedLocation or something similar). a way of doing it is just updating the relevant row in the DB for example:

    getContentResolver().update(MediaStore.Video.Media.EXTERNAL_CONTENT_URI.buildUpon().appendPath("2152").build(), cv, null, null);
    
  • to support previous versions that did support tagging

like image 59
royB Avatar answered Nov 12 '22 14:11

royB