如何添加地理标记位置图像相机
how to add geo tag location image camera
如何在拍摄照片时添加位置,例如当智能手机要拍照并且相机打开时,该位置已经在图像选择器中可用,并且在拍摄照片时,位置成为照片上的水印。这是我编写的代码
Future pickImage(ImageSource source) async {
try {
final image = await ImagePicker.pickImage(source: source);
if(image == null) return;
final imageTemporary = File(image.path);
print(imageTemporary);
setState(() => this.image = imageTemporary);
} on PlatformException catch(e) {
print('failed to pick image');
}
}
和
Container(padding: EdgeInsets.all(5),child: Row(children: [
Column(
children: [
image != null ? Image.file(image,
width: 50, height: 50, fit: BoxFit.cover,) : Text("Rumah Depan"),
Container(
margin: const EdgeInsets.fromLTRB(15, 5, 0, 0),
child: RaisedButton(
padding: EdgeInsets.all(10),
onPressed: () {
pickImage(ImageSource.camera);
},
child: Icon(Icons.camera),
),
),
您需要从该坐标中获取坐标和名称位置。
要获取坐标,请使用 geolocator。示例:
Geolocator.Position position = await Geolocator.Geolocator.getCurrentPosition(
desiredAccuracy: Geolocator.LocationAccuracy.high);
// where position has lat and lang -> LatLng(position.latitude, position.longitude)
并使用 geocoder 将坐标解析为位置名称。示例:
// From coordinates
final coordinates = new Coordinates(1.10, 45.50); // <- here set coordinates
addresses = await Geocoder.local.findAddressesFromCoordinates(coordinates);
first = addresses.first;
print("${first.featureName} : ${first.addressLine}");
要将水印等位置打印到图像中,只需将 Stack
设置为图像的父级:
Stack(
children: <Widget>[
yourImage,
Center(child: Text("text")),
]
)
如何在拍摄照片时添加位置,例如当智能手机要拍照并且相机打开时,该位置已经在图像选择器中可用,并且在拍摄照片时,位置成为照片上的水印。这是我编写的代码
Future pickImage(ImageSource source) async {
try {
final image = await ImagePicker.pickImage(source: source);
if(image == null) return;
final imageTemporary = File(image.path);
print(imageTemporary);
setState(() => this.image = imageTemporary);
} on PlatformException catch(e) {
print('failed to pick image');
}
}
和
Container(padding: EdgeInsets.all(5),child: Row(children: [
Column(
children: [
image != null ? Image.file(image,
width: 50, height: 50, fit: BoxFit.cover,) : Text("Rumah Depan"),
Container(
margin: const EdgeInsets.fromLTRB(15, 5, 0, 0),
child: RaisedButton(
padding: EdgeInsets.all(10),
onPressed: () {
pickImage(ImageSource.camera);
},
child: Icon(Icons.camera),
),
),
您需要从该坐标中获取坐标和名称位置。 要获取坐标,请使用 geolocator。示例:
Geolocator.Position position = await Geolocator.Geolocator.getCurrentPosition(
desiredAccuracy: Geolocator.LocationAccuracy.high);
// where position has lat and lang -> LatLng(position.latitude, position.longitude)
并使用 geocoder 将坐标解析为位置名称。示例:
// From coordinates
final coordinates = new Coordinates(1.10, 45.50); // <- here set coordinates
addresses = await Geocoder.local.findAddressesFromCoordinates(coordinates);
first = addresses.first;
print("${first.featureName} : ${first.addressLine}");
要将水印等位置打印到图像中,只需将 Stack
设置为图像的父级:
Stack(
children: <Widget>[
yourImage,
Center(child: Text("text")),
]
)