Gets current coords of image

This commit is contained in:
misaochan 2016-02-03 15:49:34 +13:00
parent 29cd67f500
commit f8b6575ef4
3 changed files with 19 additions and 4 deletions

View file

@ -17,6 +17,7 @@
<uses-permission android:name="android.permission.READ_SYNC_STATS"/>
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:name=".CommonsApplication"

View file

@ -1,5 +1,8 @@
package fr.free.nrw.commons.upload;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.media.ExifInterface;
import android.util.Log;
@ -10,9 +13,12 @@ public class GPSExtractor {
private String filePath;
private double decLatitude, decLongitude;
Context context;
private static final String TAG = GPSExtractor.class.getName();
public GPSExtractor(String filePath){
public GPSExtractor(String filePath, Context context){
this.filePath = filePath;
this.context = context;
}
//Extract GPS coords of image
@ -33,8 +39,16 @@ public class GPSExtractor {
}
if (exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE) == null) {
Log.d("Image", "Picture has no GPS info");
return null;
Log.d(TAG, "Picture has no GPS info");
LocationManager locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
Location getLastLocation = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
double currentLongitude = getLastLocation.getLongitude();
double currentLatitude = getLastLocation.getLatitude();
Log.d(TAG, "Current location values: Lat = " + currentLatitude + " Long = " + currentLongitude);
String currentCoords = String.valueOf(currentLatitude) + "|" + String.valueOf(currentLongitude);
return currentCoords;
}
else {
latitude = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);

View file

@ -200,7 +200,7 @@ public class ShareActivity
if (filePath != null && !filePath.equals("")) {
//extract the coordinates of image in decimal degrees
Log.d(TAG, "Calling GPSExtractor");
GPSExtractor imageObj = new GPSExtractor(filePath);
GPSExtractor imageObj = new GPSExtractor(filePath, this);
String decimalCoords = imageObj.getCoords();