Skip to content

Crash on iOS with Position Accuracy 0 #169

Description

@guysaldanha

Describe the bug

On iOS, geolocator reports a horizontal accuracy of 0 when accuracy is unavailable. Since
10.3.0 that value is converted to double.nan, which reaches flutter_map's CirclePainter
as a circle radius and crashes with "Null check operator used on a null value". The map stays
broken until the app is restarted.

The NaN itself is not the defect — it is a documented sentinel. data.dart describes accuracy
as "Set to NaN if unavailable", and the constructor permits it explicitly:

validateDouble(accuracy, 'accuracy', ge: 0, nan: true);

Commit 1c7a016 ("avoid potential 'LatLng is not finite' errors", #161) did not introduce a bad
value; it routed a supported sentinel into a path that cannot accept one. That path is a single
line — location_marker_layer.dart:39 passes accuracy straight into CircleMarker as its
radius:

if (style.showAccuracyCircle)
  CircleLayer(
    circles: [
      CircleMarker(
        point: position.latLng,
        radius: position.accuracy,   // NaN when accuracy is unavailable
        useRadiusInMeter: true,
        ...

CirclePainter then cannot look up the circle by its NaN-derived key, since NaN != NaN.

Expected behavior

An unavailable accuracy should not crash the map. Since a circle of unknown radius has nothing
meaningful to draw, the accuracy circle should be skipped when position.accuracy is not
finite, and the rest of the marker should render normally.

Note that coercing accuracy back to 0 in data.dart also stops the crash, but regresses the
#161 case that 1c7a016 fixed — hence the suggestion to guard at the render site instead.

Smartphone (please complete the following information):

  • OS: iOS
  • Version: flutter_map_location_marker 10.3.0 (not present in 10.2.0), flutter_map 8.3.1,
    geolocator 14.0.3

Additional context

Possibly the same input, unverified: current_location_layer.dart:581-587 lets NaN into
maxRadius, and max() propagates NaN, so Rect.fromCircle(..., radius: NaN).overlaps(...)
is false. The visibility check would then read the marker as off-screen whenever accuracy is
unavailable and showAccuracyCircle is on.

Consumer-side workaround, sanitizing the position stream before it reaches
CurrentLocationLayer:

LocationMarkerPosition? sanitizeLocationMarkerPosition(LocationMarkerPosition? position) {
  if (position == null || position.accuracy.isFinite) return position;
  return LocationMarkerPosition(
    latitude: position.latitude,
    longitude: position.longitude,
    accuracy: 0,
  );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions