问题描述
我正在开发一个 Android 应用程序,其中一项功能是您可以在地图上放置一个标记,其中包含相机胶卷中图像的位置。如果我选择本地存储在设备上的图像,它可以完美运行,但是从 Google 相册中选择不在我手机上的照片无法检索 GPS 数据。我有一个循环来打印元数据的所有目录,但它没有显示出来。我正在使用 https://drewnoakes.com/code/exif/ 来提取元数据。
这是我目前所拥有的:
private void chooseImage() {
Intent chooseIntent = new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
chooseIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(chooseIntent,PICK_IMAGE_REQUEST);
}
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data) {
super.onActivityResult(requestCode,resultCode,data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
filePath = data.getData();
try {
Metadata Metadata = ImageMetadataReader.readMetadata(getContentResolver().openInputStream(filePath));
GpsDirectory gpsDirectory = Metadata.getFirstDirectoryOfType(GpsDirectory.class);
GeoLocation location = gpsDirectory.getGeoLocation();
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
if (marker != null && !marker.getPosition().equals(new LatLng(lat,lng))) {
FragmentManager fm = getSupportFragmentManager();
OverwritePositionDialog overwritePositionDialog = OverwritePositionDialog.newInstance(-1,new LatLng(lat,lng));
overwritePositionDialog.show(fm,"overwrite");
} else {
final MarkerOptions options = new MarkerOptions().position(new LatLng(lat,lng)).title("New Spot").snippet(username);
mMap.addMarker(options);
moveCamera(new LatLng(lat,lng));
confirmPosition(true);
}
} else {
Glide.with(context).asBitmap().load(filePath).into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource,@Nullable Transition<? super Bitmap> transition) {
Bitmap resizedBitmap = getResizedBitmap(resource,resource.getWidth() / 3,resource.getHeight() / 3);
Glide.with(context).asBitmap().override(Target.SIZE_ORIGINAL).load(resizedBitmap).into(imagePreview);
imagePreview.animate().alpha(1f).setDuration(250);
}
});
Toast.makeText(CreateSpot.this,"Unable to get location from image.",Toast.LENGTH_SHORT).show();
}
Glide.with(context).asBitmap().load(filePath).into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource,@Nullable Transition<? super Bitmap> transition) {
Bitmap resizedBitmap = getResizedBitmap(resource,resource.getHeight() / 3);
Glide.with(context).asBitmap().override(Target.SIZE_ORIGINAL).load(resizedBitmap).into(imagePreview);
imagePreview.animate().alpha(1f).setDuration(250);
}
});
} catch (IOException e) {
Log.d("error",String.valueOf(e));
} catch (NullPointerException ne) {
Glide.with(context).asBitmap().load(filePath).into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource,resource.getHeight() / 3);
Glide.with(context).asBitmap().override(Target.SIZE_ORIGINAL).load(resizedBitmap).into(imagePreview);
imagePreview.animate().alpha(1f).setDuration(250);
}
});
Toast.makeText(CreateSpot.this,Toast.LENGTH_SHORT).show();
} catch (ImageProcessingException e) {
e.printstacktrace();
}
} else if (requestCode == CAMERA_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Glide.with(context).asBitmap().load(filePath).into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource,resource.getHeight() / 3);
Glide.with(context).asBitmap().override(Target.SIZE_ORIGINAL).load(resizedBitmap).into(imagePreview);
imagePreview.animate().alpha(1f).setDuration(250);
}
});
} else {
getContentResolver().delete(filePath,null,null);
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)