Как я могу получить местоположение пользователя с помощью MapKit?
Я пишу приложение карты для iOS 17 с помощью Xcode 15. И у меня проблема с определением местоположения пользователя.
Итак, я добавляю параметры в информацию
И я создаю Map() с помощью MapUserLocationButton().
var body: some View {
Map(scope: mapScope){
UserAnnotation()
}
.mapControls() {
VStack {
MapUserLocationButton(scope: mapScope)
MapScaleView(scope: mapScope)
}
}
.mapControlVisibility(Visibility.visible)
}
И если я нажму MapUserLocationButton, я получу ошибку:CLLocationManager(<CLLocationManager: 0x28377a500>) for <MKCoreLocationProvider: 0x280773210> did fail with error: Error Domain=kCLErrorDomain Code=1 "(null)"
Я также попытался добавить:
let locationManager = CLLocationManager()
.onAppear {
locationManagerDidChangeAuthorization(locationManager)
}
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
switch manager.authorizationStatus {
case .authorizedWhenInUse: // Location services are available.
enableLocationFeatures()
break
case .restricted, .denied: // Location services currently unavailable.
disableLocationFeatures()
break
case .notDetermined: // Authorization not determined yet.
manager.requestWhenInUseAuthorization()
break
default:
break
}
}
но это не принесло результата.
Что я делаю не так?