flutter-geolocator icon indicating copy to clipboard operation
flutter-geolocator copied to clipboard

Exception on IOS

Open tzvc opened this issue 7 years ago • 22 comments

🐛 Bug Report

I'm using the stream feature for real time location updates and I ran into an issue. When my position is fixed in the simulator, the update works normally but when I set the location to moving (simulator->debug->location->city run), an exception is thrown:

[VERBOSE-2:shell.cc(184)] Dart Error: Unhandled exception:
PlatformException(ERROR_UPDATING_LOCATION, The operation couldn’t be completed. (kCLErrorDomain error 0.), null)
#0      _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:1112:29)
#1      _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#2      _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

Expected behavior

The location updates without throwing an exception

Reproduction steps


var locationOptions =
      LocationOptions(accuracy: LocationAccuracy.high, distanceFilter: 10);

geolocator.getPositionStream(locationOptions).listen((Position position) {
      print("New pos update: $position");
      if (position != null)
        setState(() {
          _position = position;
        });
    });

Configuration

Version: 2.1.1

Platform:

  • [x] :iphone: iOS
  • [ ] :robot: Android

tzvc avatar Feb 14 '19 02:02 tzvc

I have a similar issue - Using the stream for real time location updates and I ran into an issue. When my position is fixed in the simulator, the update works normally. Update the position from debug/location a couple of times and this error occurs

[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: PlatformException(ERROR_UPDATING_LOCATION, The operation couldn’t be completed. (kCLErrorDomain error 0.), null)

Config Using geolocator: "3.0.0"

iOS Simulator (12.1) and device (12.1.4)

I am investigating this further, will update soon.

nicolasjon avatar Feb 19 '19 13:02 nicolasjon

Works correctly on iOS simulator 10.1, 11.1 using - simulator->debug->location->freeway drive

Fails on 12.1 using - simulator->debug->location->freeway drive PlatformException(ERROR_UPDATING_LOCATION, The operation couldn’t be completed.

nicolasjon avatar Feb 19 '19 14:02 nicolasjon

geolocator example Fails on 12.1

screenshot 2019-02-19 at 14 28 04

nicolasjon avatar Feb 19 '19 14:02 nicolasjon

I'm having the same problem

barthr avatar Mar 03 '19 13:03 barthr

True. It happens even with the provided example.

dxps avatar Mar 05 '19 23:03 dxps

Hi, I am seeing the same issue, but for me I tried "city bicycle ride" first, and that worked! But then it failed when switching over to "city run" with this error.

So City Bicycle Ride might be a profile you can use in the meantime.

Edit 1: And now bicycle mode stopped working as well! Edit 2: Uninstalling the app, and re-allowing location access fixed this issue for me.

FlashJonas avatar Mar 07 '19 12:03 FlashJonas

I'm seeing this as well. I did this as a work around:

  StreamSubscription<Position> _positionStream;

  void _streamLocation() {
    // TODO: initialize _positionStream
    _positionStream.onError((e) {
      print("error streaming position: $e");
      _disposePositionStream();
      _streamLocation();
    });
  }

  void _disposePositionStream() {
    if (_positionStream != null) {
      _positionStream.cancel();
      _positionStream = null;
    }
  }

Restarting the stream seems to make it work now.

NOTE: This is not the optimal way to handle this with nulling the _positionStream while it is still being used by onError.

andyvanosdale avatar Jul 06 '19 20:07 andyvanosdale

Still getting this error using the example app Single seems to work, although occasionally reports null, stream fails after a few updates.

PlatformException(ERROR_UPDATING_LOCATION, The operation couldn’t be completed. (kCLErrorDomain error 0.), null)

Config (Now) Using geolocator: "5.1.1+1"

iOS Simulator (12.4) and device (10.x.x)

nicolasjon avatar Aug 03 '19 13:08 nicolasjon

By way of a Hack test..

LocationTask.m

  • (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { NSLog(@"%s", sel_getName(_cmd)); // [[self context] resultHandler]([FlutterError errorWithCode:@"*ERROR_UPDATING_LOCATION" message:error.localizedDescription details:nil]); [self stopTask]; [self startTask]; // Forgive me... }

This works reliably on the Simulator 12.4 and 10.3 Remember the simulator Debug, Location sometimes has to be kicked a few times before it changes.

Thoughts?

nicolasjon avatar Aug 03 '19 14:08 nicolasjon

Having the same problem after updating library to latest version. After some tests we found that exceptions kicked when WiFi is on, if enable 3g it works correcty. Any solutions for this?

VladimirCourse avatar Aug 18 '19 19:08 VladimirCourse

Having a similar problem. I'm trying to complete a course from londonappbrewery. I'm getting the following exceptions! Don't know how to fix it :/

Code: Screenshot 2019-10-03 at 9 55 17 PM

As I press the button it shows:

Launching lib/main.dart on iPhone Xʀ in debug mode... Running Xcode build... Xcode build done. 24.1s Syncing files to device iPhone Xʀ... [VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: PlatformException(ERROR_UPDATING_LOCATION, The operation couldn’t be completed. (kCLErrorDomain error 0.), null) #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7) #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:316:33) #2 Geolocator.getCurrentPosition (package:geolocator/geolocator.dart:103:32) #3 _LoadingScreenState.getLocation (package:clima/screens/loading_screen.dart:12:10) #4 _LoadingScreenState.build. (package:clima/screens/loading_screen.dart:22:13) #5 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:654:14) #6 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:729:32) #7 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24) #8 <…>

I've also tried to run it on the android simulator (Pixel 3a API 28). It worked but unfortunately, it's providing incorrect coordinates. The difference in coordinates is huge. Like, I'm trying to get a location from Pakistan and its showing location somewhere in the USA.

Abdullah2050 avatar Oct 03 '19 16:10 Abdullah2050

#252 take a look at this and see if you have problems in common. Could you also provide me with some information about the course so I know what I'm looking at?

StijnWoerkom avatar Oct 11 '19 09:10 StijnWoerkom

I faced same issue, my solution is: Debug -> Location ->

Screen Shot 2019-10-17 at 4 28 02 PM

When I checked here, neither 'None' nor 'Custom Location' were selected, I selected an option as you see and it worked.

esenmx avatar Oct 17 '19 13:10 esenmx

Also seeing this for iOS devices in production on Sentry. I'm not using realtime location updates, just calls to getCurrentPosition/getLastKnownPosition

PlatformException: PlatformException(ERROR_UPDATING_LOCATION, The operation couldn’t be completed. (kCLErrorDomain error 0.), null)
  File "message_codecs.dart", line 569, in StandardMethodCodec.decodeEnvelope
  File "framework.dart", line 3919, in ComponentElement.mount
  File "framework.dart", line 3101, in Element.inflateWidget
  File "framework.dart", line 2904, in Element.updateChild
  File "framework.dart", line 5127, in SingleChildRenderObjectElement.mount
  File "framework.dart", line 3101, in Element.inflateWidget
  File "framework.dart", line 2904, in Element.updateChild
  File "framework.dart", line 3961, in ComponentElement.performRebuild
  File "framework.dart", line 3738, in Element.rebuild
  File "framework.dart", line 3924, in ComponentElement._firstBuild
  File "framework.dart", line 4088, in StatefulElement._firstBuild
  File "framework.dart", line 3919, in ComponentElement.mount
.
.
.

Ideas?

nuzelac avatar Nov 04 '19 18:11 nuzelac

The following code creates the same error for me:

import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';

class LoadingScreen extends StatefulWidget {
  @override
  _LoadingScreenState createState() => _LoadingScreenState();
}

class _LoadingScreenState extends State<LoadingScreen> {

  void getLocation() async {
    Position position = await Geolocator()
      .getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
    print(position);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RaisedButton(
          onPressed: () {
            getLocation();
          },
          child: Text('Get Location'),
        ),
      ),
    );
  }
}

Versions

Android Studio 3.5.3 Build #AI-191.8026.42.35.6010548, built on November 15, 2019 JRE: 1.8.0_202-release-1483-b49-5587405 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o macOS 10.15.2

geolocator-5.1.5 location_permissions-2.0.3 flutter version: v1.13.5

Running on similator: Iphone 11 Pro Max 13.3

As suggested by @softronaut setting the location in the simulator app will get rid of the error. So perhaps an improved error message would help. In my case the error was because no location was set.

ggeldenhuis avatar Jan 02 '20 17:01 ggeldenhuis

Having a similar problem. I'm trying to complete a course from londonappbrewery. I'm getting the following exceptions! Don't know how to fix it :/

Code: Screenshot 2019-10-03 at 9 55 17 PM

As I press the button it shows:

Launching lib/main.dart on iPhone Xʀ in debug mode... Running Xcode build... Xcode build done. 24.1s Syncing files to device iPhone Xʀ... [VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: PlatformException(ERROR_UPDATING_LOCATION, The operation couldn’t be completed. (kCLErrorDomain error 0.), null) #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7) #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:316:33)

#2 Geolocator.getCurrentPosition (package:geolocator/geolocator.dart:103:32)

#3 _LoadingScreenState.getLocation (package:clima/screens/loading_screen.dart:12:10)

#4 _LoadingScreenState.build. (package:clima/screens/loading_screen.dart:22:13) #5 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:654:14) #6 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:729:32) #7 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24) #8 <…>

I've also tried to run it on the android simulator (Pixel 3a API 28). It worked but unfortunately, it's providing incorrect coordinates. The difference in coordinates is huge. Like, I'm trying to get a location from Pakistan and its showing location somewhere in the USA.

fixed it by following the iOS Simulator -> Features -> Location -> Custom Location...

TUKenStone avatar Mar 26 '20 18:03 TUKenStone

You have to set you custom location on the simulator under features>location>custom location

tikyanatwork avatar Mar 31 '20 13:03 tikyanatwork

I faced same issue, my solution is: Debug -> Location ->

Screen Shot 2019-10-17 at 4 28 02 PM

When I checked here, neither 'None' nor 'Custom Location' were selected, I selected an option as you see and it worked.

I've had to set this option a couple of times now. For some reason every now and again the setting resets itself. Anyone know why this is?

nathanogunleye avatar May 02 '20 10:05 nathanogunleye

Updated, this is now in Features -> Location -> Select an option

darbyo avatar Jul 21 '20 23:07 darbyo

Solved in version 6.0.0

mvanbeusekom avatar Sep 04 '20 16:09 mvanbeusekom