Problem on Ios, unable to obtain location
Describe the bug I have a flutter code base which asks for location authorization and which displays this on a google map, on an android device I manage to display the location on the map but on an Ios device a blank page appears on the screen when the compiler comes to the method for getting the location, I observed this by calling the "Location" instance directly in the main
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
await NotificationController.intialisation();
final locationPermission = await Location.instance.requestPermission();
final service = await Location.instance.serviceEnabled();
final localisaton = await Location.instance.getLocation();
print("permission: $locationPermission");
print("service $service");
print("localisation $localisaton");
tz.initializeTimeZones();
runApp(const ProviderScope(child:MyApp()));
}
Expected behavior I'm waiting to see the position of the Ios device on the map the same as on Android
Tested on:
- Android, I tested on a real device with Android version 9 and on emulator version 14
- iOS, I tested on an iOS 18 simulator
Other plugins:
- maybe the flutter_local_notifications plugin
Additional logs No logs in console
some logs
same same. getLocation did not work
getLocation doesn't work on iOS, both simulator and real device, but onLocationChanged works fine
getLocation doesn't work on iOS, both simulator and real device, but onLocationChanged works fine
what is the interval for getting a location when using onLocationChanged? does it even fire if the location didn't change ? does it work on the simulator ?
getLocation doesn't work on iOS, both simulator and real device, but onLocationChanged works fine
Could you please share your code snippets where you use onLocationChanged ? It does not work for me,so I just want to verify whether I do correct or not. Thanks!
@DhvanitVaghani @hossam-96 I'm using location: ^7.0.1, I checked location permission with status always and GPS enabled before
final location = Location();
location.changeSettings(
interval: 60000,
distanceFilter: 10,
);
try {
location.enableBackgroundMode(enable: true);
} catch (error) {
printLogger("Enable Background Mode: $error");
}
// Listener position changed
_locationSubs?.cancel();
_locationSubs = location.onLocationChanged.listen(
(position) {
// It works
printLogger("Location Changed: ${position.latitude} - ${position.longitude}");
},
onError: (error) {
printLogger("Location Changed Error: $error");
},
);
// Get new location
location.getLocation().then((position) {
// It doesn't work
printLogger("Location: ${position.latitude} - ${position.longitude}");
}).catchError((error) {
printLogger("Location Error: $error");
});