@@ -21,9 +21,11 @@ class MapViewModel: ObservableObject {
2121
2222 let locationManagerDelegate = LocationManagerDelegate ( )
2323 @Published var isLoading : Bool = false
24- var region = MKCoordinateRegion ( center: CLLocationCoordinate2D ( latitude: 37.3318 , longitude: - 122.0312 ) , span: MKCoordinateSpan ( latitudeDelta: 0.0009 , longitudeDelta: 0.0009 ) )
24+ // var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 37.3318, longitude: -122.0312), span: MKCoordinateSpan(latitudeDelta: 0.0009 , longitudeDelta: 0.0009))
25+ @Published var region = MKCoordinateRegion ( )
2526 let viewSpanDelta = 0.005 // Delta lat/lng to show to the user
26- var userlocation = CLLocationCoordinate2D ( latitude: 17.4700 , longitude: 78.3534 )
27+ // var userlocation = CLLocationCoordinate2D(latitude: 17.4700, longitude: 78.3534)
28+ @Published var userlocation : CLLocationCoordinate2D ? = nil
2729 @Published var refreshMap = UUID ( )
2830 @Published var items : [ DisplayUnitWithCoordinate ] = [ ]
2931 @Published var selectedQuest : DisplayUnit ?
@@ -36,16 +38,22 @@ class MapViewModel: ObservableObject {
3638 private let dbInstance = DatabaseConnector . shared
3739
3840 init ( ) {
39- locationManagerDelegate. locationManager. delegate = locationManagerDelegate
40- locationManagerDelegate. locationManager. requestWhenInUseAuthorization ( )
41- locationManagerDelegate. locationManager. startUpdatingLocation ( )
42-
43- locationManagerDelegate. locationUpdateHandler = { [ weak self] location in
44- guard let self = self else { return }
45- self . userlocation = location
46- fetchOSMDataFor ( from: . currentLocation( location: location) )
47- }
48- }
41+ locationManagerDelegate. locationUpdateHandler = { [ weak self] location in
42+ guard let self = self else { return }
43+
44+ DispatchQueue . main. async {
45+ self . userlocation = location
46+ self . region = MKCoordinateRegion (
47+ center: location,
48+ span: MKCoordinateSpan ( latitudeDelta: self . viewSpanDelta, longitudeDelta: self . viewSpanDelta)
49+ )
50+ self . fetchOSMDataFor ( from: . currentLocation( location: location) )
51+ }
52+ }
53+
54+ locationManagerDelegate. requestLocationAuthorization ( )
55+ locationManagerDelegate. startUpdatingLocation ( )
56+ }
4957
5058 func getSelectedQuest( ) -> DisplayUnit ? {
5159 if isMultiSelectModeEnabled {
0 commit comments