如何解决ExifInterface getLatlong在Kotlin中不起作用
我尝试从捕获的图像中获取经度和纬度 但是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 举报,一经查实,本站将立刻删除。