0

I'm using for a way to update an annotation programmatically. I'm playing with SwiftUI and UIViewRepresentable. The map is shown. It is also not a problem to display an annotation on the map.

What I need now is this: I'm having a location provider, which delivers CLLocation2D coordinates. I would like to display the changing position on a map, but can't figure out how.

The location update is provided via an ObservableObject. That works. If I display the updates in Text element, I can see them:

@ObservedObject var pushedPoseClient = PushedPosesClient()
...
Text(String(format: "%.10f %.10f", self.pushedPoseClient.position.latitude ?? 0, self.pushedPoseClient.position.longitude ?? 0))

The same mechanism doesn't work for a map. I thought I could see updateUIView calls with every position update, but there are no.

How can an ObservedObject, which changes its coordinates, be displayed on a map?

decades
  • 827
  • 17
  • 25
  • Found a hint here https://stackoverflow.com/questions/57478134/how-to-update-uiviewrepresentable-with-observableobject. That works – decades Jan 27 '20 at 14:18

1 Answers1

1

The key is to have a CLLocation2D as observed object. Then it works.

decades
  • 827
  • 17
  • 25