flutterimagepickergeotagging

how to add geo tag location image camera


how to add the location when the photo was taken, for example when the smartphone wants to take a picture and the camera is open then the location is already available in the image picker and when the photo is taken, the location becomes a watermark on the photo. here's the code I made

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');
}

}

and

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),
                  ),
                     ),

Solution

  • You need to get the coordinates and name location from that coordinates. To get coordinates use geolocator. Example:

    Geolocator.Position position = await Geolocator.Geolocator.getCurrentPosition(
                  desiredAccuracy: Geolocator.LocationAccuracy.high);
    // where position has lat and lang -> LatLng(position.latitude, position.longitude)
    

    And to parse coordinates to location name use geocoder. Example:

    // 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}");
    

    To print location like watermark into image just set Stack as parent of image:

    Stack(
        children: <Widget>[
            yourImage,
            Center(child: Text("text")),
        ]
    )