I discovered that my previous problem was related to the Camera permissions of the devices. Usually a camera from android access the user location and save the GPS coordinates as Exif tag, but the ios devices usually don’t save this by default unless the user allows location permissions to the camera app.
I changed my app to check if the image has GPS coordinates and the user decides if he wants to share his actual location or the image location.
I’m also having to do some math to process the coordinates:
In order to you use the code you have to add the package exif and geoflutterfire
to your app.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | void _checkGPSData() async { Map<String, IfdTag> imgTags = await readExifFromBytes( File(image.path).readAsBytesSync() ); if (imgTags.containsKey('GPS GPSLongitude')) { setState(() { _imgHasLocation = true; _imgLocation = exifGPSToGeoFirePoint(imgTags); }); } } GeoFirePoint exifGPSToGeoFirePoint(Map<String, IfdTag> tags) { final latitudeValue = tags['GPS GPSLatitude'].values.map<double>( (item) => (item.numerator.toDouble() / item.denominator.toDouble()) ).toList(); final latitudeSignal = tags['GPS GPSLatitudeRef'].printable; final longitudeValue = tags['GPS GPSLongitude'].values.map<double>( (item) => (item.numerator.toDouble() / item.denominator.toDouble()) ).toList(); final longitudeSignal = tags['GPS GPSLongitudeRef'].printable; double latitude = latitudeValue[0] + (latitudeValue[1] / 60) + (latitudeValue[2] / 3600); double longitude = longitudeValue[0] + (longitudeValue[1] / 60) + (longitudeValue[2] / 3600); if (latitudeSignal == 'S') latitude = -latitude; if (longitudeSignal == 'W') longitude = -longitude; return GeoFirePoint(latitude, longitude); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.