I'm collecting GPS data via the Geolocator package and converting the data to an address via the Geocoding package. Upon converting the GPS location to an address, while running the iOS Simulator I receive the following error:
flutter: error DatabaseException(Error Domain=FMDatabase Code=11 "database disk image is malformed" UserInfo={NSLocalizedDescription=database disk image is malformed}) sql 'BEGIN EXCLUSIVE' args [] during open, closing...
I also ran the Android Emulator to see if it's related to iOS or if I could get a better explanation about the error. The emulator outputs a different error message:
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(IO_ERROR, A network error occurred trying to lookup the supplied coordinates (latitude: 37.421998, longitude: -122.084000)., null, null)
void initState() {
super.initState();
_requestPermission()
.then((_) => getPositionStream())
.catchError((error) => print(error.toString()));
currentUser = Provider.of<UserData>(context, listen: false).currentUserId;
_jobStream = FirebaseFirestore.instance
.collection('jobs')
.doc(widget.edittingJob.documentId)
.snapshots();
}
Future getPositionStream() async {
LocationSettings locationSettings;
if (defaultTargetPlatform == TargetPlatform.android) {
locationSettings = AndroidSettings(
accuracy: LocationAccuracy.high,
distanceFilter: 10,
forceLocationManager: true,
intervalDuration: const Duration(seconds: 1),
);
} else if (defaultTargetPlatform == TargetPlatform.iOS ||
defaultTargetPlatform == TargetPlatform.macOS) {
locationSettings = AppleSettings(
accuracy: LocationAccuracy.high,
distanceFilter: 10,
pauseLocationUpdatesAutomatically: true,
);
} else {
locationSettings = LocationSettings(
accuracy: LocationAccuracy.high,
distanceFilter: 10,
);
}
_positionStream =
Geolocator.getPositionStream(locationSettings: locationSettings)
.listen((Position position) async {
List placeMarks =
await placemarkFromCoordinates(position.latitude, position.longitude);
setState(() {
_address = placeMarks[0].street.toString() +
', ' +
placeMarks[0].locality.toString() +
', ' +
placeMarks[0].administrativeArea.toString() +
', ' +
placeMarks[0].postalCode.toString() +
', ' +
placeMarks[0].country.toString();
});
});
}
Future<void> _requestPermission() async {
bool serviceEnabled;
LocationPermission permission;
serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
return Future.error('Location services are disabled.');
}
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
return Future.error('Location permissions are denied');
}
}
if (permission == LocationPermission.deniedForever) {
return Future.error(
'Location permissions are permanently denied, we cannot request permissions.');
}
}
Very grateful for any advise!