Ich versuche, Google Location-Daten zum EXIF-Header der Bilder hinzuzufügen, die in meiner Anwendung aufgenommen wurden. Bis jetzt bin ich in der Lage, den Standort unter Verwendung fused location provider zu erhalten und es in der MainActivity zu rösten. Aber wenn ich versuche, die Positionsdaten in den EXIF-Header der Bilder zu schreiben, die in einem Thread aufgenommen wurden, kann ich das Location-Objekt dort nicht finden. Es zeigt 'Cannot resolve symbol 'location'
. Jede Hilfe wird geschätzt.Symbol kann nicht aufgelöst werden. Es konnten keine Standortdaten zu EXIF eines Bildes hinzugefügt werden.
MainActivity.java
private TestThread myThread;
private FusedLocationProviderClient mFusedLocationClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getSupportActionBar().hide();
setContentView(R.layout.activity_main);
System.loadLibrary("NativeImageProcessor");
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
mFusedLocationClient.getLastLocation()
.addOnSuccessListener(this, new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
// Got last known location. In some rare situations this can be null.
if (location != null) {
// ...
double latitude = location.getLatitude();
double longitude = location.getLongitude();
Toast.makeText(MainActivity.this, "Latitude:" + latitude+", Longitude:"+longitude,Toast.LENGTH_SHORT).show();
}
}
});
...
...
takePicture();
TestThread.java
....
private void saveBitmap(String name, Bitmap bitmap, String timeStamp) {
File photo = CommonUtil.getFileName(timeStamp, name);
if (photo.exists()) photo.delete();
try {
Bitmap image = applyBrightnessContrast(bitmap);
FileOutputStream fos = new FileOutputStream(photo.getPath());
image.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.close();
CommonUtil.showProgressDialog(mContext, null, false);
} catch (java.io.IOException e) {
CommonUtil.showProgressDialog(mContext, null, false);
Log.e("PictureDemo", "Exception in photoCallback", e);
}
markGeoTagImage(photo.getPath(),location);// Here is the Error.
}
public static void markGeoTagImage(String imagePath,Location location)
{
try {
ExifInterface exif = new ExifInterface(imagePath);
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, GPS.convert(location.getLatitude()));
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, GPS.latitudeRef(location.getLatitude()));
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, GPS.convert(location.getLongitude()));
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, GPS.longitudeRef(location.getLongitude()));
SimpleDateFormat fmt_Exif = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
exif.setAttribute(ExifInterface.TAG_DATETIME,fmt_Exif.format(new Date(location.getTime())));
exif.saveAttributes();
} catch (IOException e) {
e.printStackTrace();
}
}
try Ihren empfangenen Standort in onSuccess zu einem globalen Attribute zu übergeben und Ihr globales Attribut in markGeoTagImage – MHP
Wie verwenden 'public static String = null;' in der Aktivität ?? Es wäre großartig, wenn Sie es im Code erklären. –
Ich poste die Antwort für Sie, Sie sollten das Objekt vom Typ Location definieren und es in onSuccess initialisieren, wenn die Position – MHP