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

Location doesn't work on IOS emulator #453

Closed
LarryJing opened this issue Jun 4, 2020 · 12 comments
Closed

Location doesn't work on IOS emulator #453

LarryJing opened this issue Jun 4, 2020 · 12 comments
Labels
platform: ios Issue is related to the iOS platform status: in progress Indicates that this issue is currently being worked on. type: bug Something isn't working

Comments

@LarryJing
Copy link

🐛 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:
📱 iOS

@mvanbeusekom
Copy link
Member

@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

@mvanbeusekom mvanbeusekom added platform: ios Issue is related to the iOS platform status: needs more info We need more information before we can continue work on this issue. labels Jun 4, 2020
@mitLinkwok
Copy link

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

@aya-eiya
Copy link

aya-eiya commented Jun 4, 2020

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 (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

@aya-eiya
Copy link

aya-eiya commented Jun 4, 2020

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

@kundanlal555
Copy link

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

@MisterJimson
Copy link

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.

@mvanbeusekom
Copy link
Member

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

@mvanbeusekom
Copy link
Member

mvanbeusekom commented Jun 4, 2020

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.

@mvanbeusekom mvanbeusekom reopened this Jun 4, 2020
@mvanbeusekom mvanbeusekom added status: in progress Indicates that this issue is currently being worked on. type: bug Something isn't working and removed status: needs more info We need more information before we can continue work on this issue. labels Jun 4, 2020
@mvanbeusekom
Copy link
Member

Confirmed fix, closing the issue.

@normancarcamo
Copy link

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?

@markbeij
Copy link

@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..

@mvanbeusekom
Copy link
Member

@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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: ios Issue is related to the iOS platform status: in progress Indicates that this issue is currently being worked on. type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants