Flutter-geolocator: Location doesn't work on IOS emulator

Created on 4 Jun 2020  ·  12Comments  ·  Source: Baseflow/flutter-geolocator

🐛 Bug Report

Expected behavior

Expect to print the position, this is the code:
Geolocator geo = Geolocator();
Position pos =
await geo.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
print(pos);

Reproduction steps

It works on the Android emulator-position gets printed to console.
Doesn't work on iOS emulator, nothing gets printed and if I add another print statement after print(pos), it doesn't print either. I'm guessing it never got the position so its "await"ing forever?

Configuration

iPhone 11 emulator on Android studio

Version: 1.x

Platform:
:iphone: iOS

ios in progress bug

Most helpful comment

@LarryJing I cannot reproduce this problem, did you actually simulate location updates? On the iOS simulator you need to actively set a location using the following menu option: "Features" -> "Location":

Screenshot 2020-06-04 at 13 21 49

All 12 comments

@LarryJing I cannot reproduce this problem, did you actually simulate location updates? On the iOS simulator you need to actively set a location using the following menu option: "Features" -> "Location":

Screenshot 2020-06-04 at 13 21 49

yes, I have also got an error on this plugin in ios simulator. i am getting this log on console.
Screenshot 2020-06-04 at 6 42 49 PM

yes, I have also got an error on this plugin in ios simulator. i am getting this log on console.
Screenshot 2020-06-04 at 6 42 49 PM

I have got same error too.

```flutter doctor
[✓] Flutter (Channel stable, v1.17.2, on Mac OS X 10.15.4 19E287, locale en-JP)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)

[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
[✓] Android Studio (version 4.0)
[!] IntelliJ IDEA Ultimate Edition (version 2018.2.2)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.45.1)
[✓] Connected device (1 available)
```

version:geolocator: 5.3.2

simulator: iPhone 11 / Software Version 13.5

the error does not occur when the module version change to 5.3.1.

Screenshot 2020-06-04 at 8 15 06 PM
By adding location update permission ,this issue solve

I am also running into this. I do not want to request location in the background, only foreground. I would hope that means I shouldn’t need to enable a background mode.

This is indeed an error that went live by mistake. I will correct it later today/ tomorrow. Until then either enable location updates in the background or stick with 5.3.1

I have just released a hotfix (version 5.3.2+1) which should fix this issue. The option to enable Backgroup location updates is now configurable using the EnableBackgroundLocationUpdates key in your Info.plist (see also the README.md in the iOS section).

Thanks everybody for helping debug this. Please let me know if it works correctly again.

Confirmed fix, closing the issue.

Hi there, I'm new here using geolocation services with flutter and I've found this project, looks good, but I have a problem when I try to get the current location, the application stops and it gets closed after pressing a simple button to get the location...

This is the current code I use in the onPress event handler in a dummy class:

GeolocationStatus geolocationStatus  = await Geolocator().checkGeolocationPermissionStatus();

if (geolocationStatus == GeolocationStatus.granted) {
  Position position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
  print('position $position');
}

and this is the version of the package I'm using in pubspec.yaml:

geolocator: ^5.3.2+2

And these are the keys I have added to the info.plist file:

  <!-- ...skipped by brevity -->
  <key>EnableBackgroundLocationUpdates</key>
  <true/>
  <key>NSLocationWhenInUseUsageDescription</key>
  <string>This app needs access to location when open.</string>
  <key>NSLocationAlwaysUsageDescription</key>
  <string>This app needs access to location when in the background.</string>
  <key>NSLocationAlwaysAndWhenInUsageDescription</key>
  <string>Always And In Use Permission</string>
  <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
  <string>This app needs access to location when open and in the background.</string>
  <!-- skipped by brevity... -->

@mvanbeusekom any idea of what do you think I'm doing wrong?

@mvanbeusekom, the link doesn't seem to work and other then this issue, I can't find any reference regarding EnableBackgroundLocationUpdates. Love this package btw..

@markbeij, correct the link mentioned was part of the 5.3.1 release. Currently we are on a much improved version 6.1.6 which has an updated folder structure to support the federated plugin architecture (which makes things easier to support multiple platforms).

The current link to the README.md is: https://github.com/Baseflow/flutter-geolocator/blob/master/README.md

The section regarding the background mode is:

If you would like to receive updates when your App is in the background, you'll also need to add the Background Modes capability to your XCode project (Project > Signing and Capabilities > "+ Capability" button) and select Location Updates. Be careful with this, you will need to explain in detail to Apple why your App needs this when submitting your App to the AppStore. If Apple isn't satisfied with the explanation your App will be rejected.

This will basically add the EnableBackgroundLocationUpdates parameter to your Info.plist. Note that the geolocator doesn't support running in the background and it doesn't provide any way to receive updates while running in the background. At the moment the only thing EnableBackgroundLocationUpdates will do is tell the platform to keep on listening to location updates on the platform while the app is in the background (nothing gets called or executed otherwise).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Sammius picture Sammius  ·  4Comments

shrishti08 picture shrishti08  ·  3Comments

seakmengc picture seakmengc  ·  3Comments

prasant10050 picture prasant10050  ·  6Comments

hectorAguero picture hectorAguero  ·  5Comments