mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Gets current coords of image
This commit is contained in:
parent
29cd67f500
commit
f8b6575ef4
3 changed files with 19 additions and 4 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue