I have a map where I am using UserAnnotation() to show the user's location. Location permissions are handled elsewhere in the app. If the user has previously granted location permission, that is enough for the UserAnnotation() blue pin to appear. Otherwise, it just doesn't draw.
So the Map already knows the user's permission and location without my code again requesting location etc.
I was looking for a way to leverage the map's knowledge of the user's location and came across this struct as described in the Documentation for SwiftUI Mapkit
public struct UserLocation { public var heading: CLHeading? public var location: CLLocation? }
I thought this struct might expose the user's location, but how it is expected to be used or when it should populated is unknown from the point of the documentation.
Would someone please share the purpose and use of this struct?
UserLocation
is paired with UserAnnotation
. You're using the version with the default initializer, but UserAnnotation
also has an initialized with a content
closure, which allows you to specify a custom view to represent the user annotation. A UserLocation
is passed into this content
closure as a parameter, so you could take in the heading information as part of the custom view, as an example.
—Ed Ford, DTS Engineer