image_picker 没有在颤动中拾取 GPS
我正在尝试制作一个在其元数据中包含 GPS 数据的相机应用程序。因此,我使用 image_picker 包。但是,当我使用 exif 提取元数据时,它不显示 GPS 属性。
我正在编写这样的代码:
class MyCamera extends StatefulWidget {
@override
_MyCameraState createState() => _MyCameraState();
}
class _MyCameraState extends State<MyCamera> {
String dirPath = '';
File? imageFile;
_initialImageView() {
if (imageFile == null) {
return const Text(
'No Image Selected...',
style: TextStyle(fontSize: 20.0),
);
} else {
return Card(child: Image.file(imageFile!, width: 400.0, height: 400));
}
}
_openGallery(BuildContext context) async {
var picture = await ImagePicker().pickImage(source: ImageSource.gallery);
setState(() {
imageFile = File(picture!.path);
dirPath = picture.path;
print('path');
print(dirPath);
});
}
_openCamera(BuildContext context) async {
var picture = await ImagePicker().pickImage(source: ImageSource.camera);
var bytes = await picture!.readAsBytes();
var tags = await readExifFromBytes(bytes);
tags.forEach((key, value) => print("$key : $value"));
setState(() {
imageFile = File(picture.path);
dirPath = picture.path;
print('path');
print(dirPath);
});
}
Future<void> _showChoiceDialog(BuildContext context) {
return showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Take Image From...'),
content: SingleChildScrollView(
child: ListBody(
children: [
GestureDetector(
child: const Text('Gallery'),
onTap: () {
_openGallery(context);
Navigator.of(context).pop();
},
),
const Padding(padding: EdgeInsets.all(8.0)),
GestureDetector(
child: const Text('Camera'),
onTap: () {
_openCamera(context);
Navigator.of(context).pop();
},
),
],
),
),
);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('View Image'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_initialImageView(),
Column(
children: [
Container(
margin: const EdgeInsets.symmetric(horizontal: 30.0),
width: 250.0,
child: FlatButton(
child: const Text(
'Select Image',
style: TextStyle(color: Colors.white, fontSize: 16.0),
),
onPressed: () {
_showChoiceDialog(context);
},
),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(30.0),
),
),
],
),
],
),
),
);
}
}
这些是我得到的元数据。没有准确的GPS数据我不知道我做错了什么。谁能建议我缺少什么?
I am trying to make a camera app that has GPS data in its metadata. For that reason, I am using the image_picker package. But when I extract the metadata with exif it does not show the GPS properties.
I am writing code like this:
class MyCamera extends StatefulWidget {
@override
_MyCameraState createState() => _MyCameraState();
}
class _MyCameraState extends State<MyCamera> {
String dirPath = '';
File? imageFile;
_initialImageView() {
if (imageFile == null) {
return const Text(
'No Image Selected...',
style: TextStyle(fontSize: 20.0),
);
} else {
return Card(child: Image.file(imageFile!, width: 400.0, height: 400));
}
}
_openGallery(BuildContext context) async {
var picture = await ImagePicker().pickImage(source: ImageSource.gallery);
setState(() {
imageFile = File(picture!.path);
dirPath = picture.path;
print('path');
print(dirPath);
});
}
_openCamera(BuildContext context) async {
var picture = await ImagePicker().pickImage(source: ImageSource.camera);
var bytes = await picture!.readAsBytes();
var tags = await readExifFromBytes(bytes);
tags.forEach((key, value) => print("$key : $value"));
setState(() {
imageFile = File(picture.path);
dirPath = picture.path;
print('path');
print(dirPath);
});
}
Future<void> _showChoiceDialog(BuildContext context) {
return showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Take Image From...'),
content: SingleChildScrollView(
child: ListBody(
children: [
GestureDetector(
child: const Text('Gallery'),
onTap: () {
_openGallery(context);
Navigator.of(context).pop();
},
),
const Padding(padding: EdgeInsets.all(8.0)),
GestureDetector(
child: const Text('Camera'),
onTap: () {
_openCamera(context);
Navigator.of(context).pop();
},
),
],
),
),
);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('View Image'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_initialImageView(),
Column(
children: [
Container(
margin: const EdgeInsets.symmetric(horizontal: 30.0),
width: 250.0,
child: FlatButton(
child: const Text(
'Select Image',
style: TextStyle(color: Colors.white, fontSize: 16.0),
),
onPressed: () {
_showChoiceDialog(context);
},
),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(30.0),
),
),
],
),
],
),
),
);
}
}
These are the metadata I am getting. There is no accurate GPS data I don't know what I am doing wrong. Can anyone suggest what I am missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论