Map Annotation closure does not seem to be excuted if annotationItems' id remain the same

I have a Map in in my view as following:

Code Block swift
         Map(coordinateRegion: coordinateRegion, annotationItems: mapsVM.coordinates) { coordinate in
          MapAnnotation(coordinate: coordinate.coordinate, anchorPoint: CGPoint(x: 0.5, y: 0.5)) {
            Circle()
              .strokeBorder(Color.red, lineWidth: 10)
              .frame(width: 20, height: 20)
          }
        }

and I have a ObservableObject in this view struct
Code Block swift
@ObservedObject var mapsVM: MapsVM


MapsVM has a property:
Code Block swift
   @Published var coordinates: [MapCoordinate]

which was used as annotation item. And its first element is used to be the center of coordinateRegion.
Map Coordinate is as following:

Code Block swift
struct MapCoordinate: Identifiable {
  let id: Int
  let latitude: Double
  let longitude: Double
  var coordinate: CLLocationCoordinate2D {
    CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
  }
}

The weird thing happens. When I set the coordinates in mapsVM, which will publish and redraw the view.
Code Block swift
coordinates[0] = MapCoordinate(id: 0, latitude: newLatitude, longitude: newLongitude)

The map region gets updated but the annotation never gets added:
Code Block swift
Map(coordinateRegion: coordinateRegion, annotationItems: mapsVM.coordinates)

is called again, but its trailing closure
Code Block swift
{ coordinate in
          MapAnnotation(coordinate: coordinate.coordinate, anchorPoint: CGPoint(x: 0.5, y: 0.5)) {
            Circle()
              .strokeBorder(Color.blue, lineWidth: 10)
              .frame(width: 20, height: 20)
          }
        }

was never invoked again. This causes the map only updates the region but never adds the annotation. Then I found a solution: if I set the id of MapCoordinate to UUID:
Code Block swift
struct MapCoordinate: Identifiable {
  let id = UUID()
  let latitude: Double
  let longitude: Double
  var coordinate: CLLocationCoordinate2D {
    CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
  }
}

The annotation gets updated correctly now (each coordinates array assignment replaces it's first element with a new MapCoordinate, hence each assignment result in new UUID). Is this a bug? If the annotationItem's id remian the same, the Map view simply does not update the annotations.




Could you please try with the latest iOS 15 beta build and if the issue still persists please file a report via Feedback Assistant (https://feedbackassistant.apple.com/).

Map Annotation closure does not seem to be excuted if annotationItems' id remain the same
 
 
Q