Flutter-geolocator: Exception on IOS

Created on 14 Feb 2019  Ā·  21Comments  Ā·  Source: Baseflow/flutter-geolocator

šŸ› 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
ios bug up for graps

Most helpful comment

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.

All 21 comments

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.

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.

geolocator example Fails on 12.1

screenshot 2019-02-19 at 14 28 04

I'm having the same problem

True. It happens even with the provided example.

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.

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.

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)

By way of a Hack test..

LocationTask.m

  • (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    NSLog(@"%s", sel_getName(_cmd));
    // [self context] resultHandler;
    [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?

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?

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.

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?

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.

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?

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.

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

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

locationManager:didUpdateLocations:
[CurrentLocationTask dealloc]
[LocationTask dealloc]

I followed iOS Simulator -> Features -> Location -> Custom Location and now I am getting the above message. What is this?

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?

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

Solved in version 6.0.0

Was this page helpful?
0 / 5 - 0 ratings