Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem on Ios, unable to obtain location #1005

Open
abdoul-kader1 opened this issue Nov 5, 2024 · 5 comments
Open

Problem on Ios, unable to obtain location #1005

abdoul-kader1 opened this issue Nov 5, 2024 · 5 comments

Comments

@abdoul-kader1
Copy link

abdoul-kader1 commented Nov 5, 2024

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
@yanashenyang
Copy link

same same. getLocation did not work

@thang510023
Copy link

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

@hossam-96
Copy link

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 ?

@DhvanitVaghani
Copy link

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!

@thang510023
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants