I've been playing around with this package and I was wondering if there is a way to add a button which sets the camera to the user's location. My first thought would have been:
struct MainMapView: View {
@State private var camera = MapViewCamera.trackUserLocationWithHeading(zoom: 10)
var body: some View {
MapView(
styleURL: styleURL,
camera: $camera,
locationManager: locationManager
)
.mapUserAnnotationStyle(
.init(
approximateHaloBorderColor: .blue,
approximateHaloBorderWidth: 50,
approximateHaloFillColor: .blue,
approximateHaloOpacity: 0.5,
haloFillColor: .blue,
puckArrowFillColor: .blue,
puckFillColor: .blue,
puckShadowColor: .white,
puckShadowOpacity: 0.5
)
)
.overlay(alignment: .leading, content: {
Button("Go to location") {
camera = MapViewCamera.trackUserLocationWithHeading(zoom: 10)
}
})
.onAppear {
locationService.requestWhenInUseAuthorization()
locationService.startUpdatingLocation()
locationService.startUpdatingHeading()
}
}
}
... but this only seems to work some of the time: specifically, only after the camera has updated (from a pan, zoom, etc.); it will not update during a pan.
Just wondering if there is an intended way to implement this kind of behaviour?
I've been playing around with this package and I was wondering if there is a way to add a button which sets the camera to the user's location. My first thought would have been:
... but this only seems to work some of the time: specifically, only after the camera has updated (from a pan, zoom, etc.); it will not update during a pan.
Just wondering if there is an intended way to implement this kind of behaviour?