tlserver / flutter_map_location_marker

A flutter map plugin for displaying device current location.
https://pub.dev/packages/flutter_map_location_marker
BSD 3-Clause "New" or "Revised" License
102 stars 93 forks source link

iOS [CoreLocation] This method can cause UI unresponsiveness if invoked on the main thread. #79

Closed RedHappyLlama closed 11 months ago

RedHappyLlama commented 1 year ago

Hi,

The following code produces an error: [CoreLocation] This method can cause UI unresponsiveness if invoked on the main thread. Instead, consider waiting for the `-locationManagerDidChangeAuthorization:` callback and checking `authorizationStatus` first.

          FollowOnLocationUpdate _centerOnLocationUpdate = FollowOnLocationUpdate.never;
          late StreamController<double> _centerCurrentLocationStreamController;

          @override
          void initState() {
          super.initState();
          _centerOnLocationUpdate = FollowOnLocationUpdate.always;
          _centerCurrentLocationStreamController = StreamController<double>();
           }

....

        child: FlutterMap(
          mapController: mapController,
          options: MapOptions(
            center: LatLng(centerLat, centerLng),
            zoom: _zoom,
            enableMultiFingerGestureRace: true,
            maxZoom: 18,
            minZoom: 4.0,
            onTap: (context, latLng) {
              _popupLayerController.hideAllPopups();
              selectedGuide = null;
            },
            onPositionChanged: (MapPosition position, bool hasGesture) {
              _popupLayerController.hideAllPopups();
              if (hasGesture) {
                setState(() => _centerOnLocationUpdate = FollowOnLocationUpdate.never);
              }
            },
          ),
          children: [
              CurrentLocationLayer(
                followCurrentLocationStream: _centerCurrentLocationStreamController.stream,
                followOnLocationUpdate: _centerOnLocationUpdate,
                style: LocationMarkerStyle(
                  marker: Container(
                    decoration: BoxDecoration(
                      color: myBlueColour,
                      borderRadius: BorderRadius.circular(30.0),
                      border: Border.all(style: BorderStyle.solid, color: Colors.white, width: 5.0),
                    ),
                  ),
                  markerSize: const Size(25.0, 25.0),
                  accuracyCircleColor: myBlueColourTransparent,
                  headingSectorColor: myBlueColour,
                ),
              ),

May be related to https://github.com/Baseflow/flutter-geolocator/issues/1151.

Any help would be much appreciated.

tlserver commented 1 year ago

Can you provide more information, such as which system / platform, which version of OS & flutter & FMLM & FM?

RedHappyLlama commented 1 year ago

Can you provide more information, such as which system / platform, which version of OS & flutter & FMLM & FM?

Apologies for the delay! Details below:

tlserver commented 1 year ago

Sorry, I do not have a iOS device to test it. If you found this problem is caused by this plugin but not its dependency, a PR would be help. Otherwise, you may want to create an issue in that reso and close this.

RedHappyLlama commented 1 year ago

Hi,

I get around the issue with the code below which might help? I believe the issue might be related to using an old version of the iOS Geolocator problem. See https://github.com/Baseflow/flutter-geolocator/issues/1151. Unfortunately I'm relatively new to coding and Flutter so not sure I can be much more help right now?

              Platform.isIOS
                  ? CurrentLocationLayer(
                      //TODO eventually remove this
                      positionStream: Geolocator.getPositionStream().asyncMap(
                        (event) => LocationMarkerPosition(
                            latitude: event.latitude,
                            longitude: event.longitude,
                            accuracy: event.accuracy),
                      ),
                      followCurrentLocationStream: _centerCurrentLocationStreamController.stream,
                      followOnLocationUpdate: _centerOnLocationUpdate,
                      style: LocationMarkerStyle(
                        marker: Container(
                          decoration: BoxDecoration(
                            color: myBlueColour,
                            borderRadius: BorderRadius.circular(30.0),
                            border: Border.all(style: BorderStyle.solid, color: Colors.white, width: 5.0),
                          ),
                        ),
                        markerSize: const Size(25.0, 25.0),
                        accuracyCircleColor: myBlueColourTransparent,
                        headingSectorColor: myBlueColour,
                      ),
                    )
github-actions[bot] commented 11 months ago

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

RedHappyLlama commented 11 months ago

@tlserver, any update on this? Thanks!

tlserver commented 11 months ago

I have bought an iPad to test. I simply delete CurrentLocationLayer in default stream example and still see this error. That mean this issue is caused by geolocation, so no work can do on this plugin. So I am closing this, subscribe Baseflow/flutter-geolocator#1151 if you want to be updated.