decades
decades

Reputation: 827

Position update in SwiftUI with MKMapKit

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?

Upvotes: 0

Views: 485

Answers (1)

decades
decades

Reputation: 827

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

Upvotes: 1

Related Questions