问题描述
我尝试从捕获的图像中获取经度和纬度 但是ExifInterface.getLatlong返回false
我添加了权限,但是没有用
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION"/>
<uses-feature android:name="android.hardware.camera" android:required="true"/>
现在文件图像显示良好,但是var haslatlong始终为false 如何获得经纬度?
@RequiresApi(Build.VERSION_CODES.N)
override fun onActivityResult(requestCode: Int,resultCode: Int,data: Intent?) {
super.onActivityResult(requestCode,resultCode,data)
if(requestCode == REQUEST_IMAGE_CAPTURE && resultCode == Activity.RESULT_OK){
val bitmap: Bitmap
val file = File(curPhotoPath)
if(Build.VERSION.SDK_INT < 28)
{
val content = contentResolver.openInputStream(Uri.fromFile(file))
val location = ExifInterface(content)
var latlong = floatArrayOf()
var hasLatlong = false
hasLatlong = location.getLatLong(latlong)
if(hasLatlong) {
Log.e("lat",latlong[0].toString())
Log.e("long",latlong[1].toString())
}
}
else
{
val decode = imagedecoder.createSource(
this.contentResolver,Uri.fromFile(file)
)
val content = contentResolver.openInputStream(Uri.fromFile(file))
val location = ExifInterface(content)
var latlong = floatArrayOf(2F)
var hasLatlong = true
hasLatlong = location.getLatLong(latlong)
if(hasLatlong) {
Log.e("lat",latlong[1].toString())
}
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)