flutterlocation icon indicating copy to clipboard operation
flutterlocation copied to clipboard

Problem on Ios, unable to obtain location

Open abdoul-kader1 opened this issue 1 year ago • 5 comments

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

abdoul-kader1 avatar Nov 05 '24 12:11 abdoul-kader1

same same. getLocation did not work

yanashenyang avatar Dec 06 '24 07:12 yanashenyang

getLocation doesn't work on iOS, both simulator and real device, but onLocationChanged works fine

thang510023 avatar Dec 10 '24 10:12 thang510023

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 ?

hossam-96 avatar Dec 11 '24 20:12 hossam-96

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 avatar Dec 12 '24 17:12 DhvanitVaghani

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

thang510023 avatar Dec 16 '24 07:12 thang510023