Skip to content

Commit 0540de3

Browse files
author
Achyut Kumar M
committed
remove default location
1 parent 53a39a3 commit 0540de3

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

GoInfoGame/GoInfoGame/LocationManagerDelegate.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class LocationManagerDelegate: NSObject, ObservableObject, CLLocationManagerDele
1616
var locationUpdateHandler: ((CLLocationCoordinate2D) -> Void)?
1717
var headingUpdateHandler: ((Double) -> Void)?
1818

19+
var coordinate: CLLocationCoordinate2D? {
20+
location?.coordinate
21+
}
22+
1923
override init() {
2024
super.init()
2125
locationManager.delegate = self

GoInfoGame/GoInfoGame/UI/Map/CustomMap.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import osmparser
1515
struct CustomMap: UIViewRepresentable {
1616

1717
var region: MKCoordinateRegion
18-
var userLocation = CLLocationCoordinate2D(latitude: 17.4700, longitude: 78.3534)
1918
@Binding var trackingMode: MapUserTrackingMode
2019
@Binding var items: [DisplayUnitWithCoordinate]
2120
@Binding var selectedQuest: DisplayUnit?
@@ -484,15 +483,14 @@ struct CustomMap: UIViewRepresentable {
484483
}
485484

486485
// Check for modals or settings before changing map
487-
if isPresented || isUserSettingsPresented {
486+
if isPresented {
488487
return
489488
}
490489

491490
// ✅ Only if no annotations and safe state
492-
if existingCoordinates.isEmpty && !context.coordinator.isCenteredOnUser {
493-
mapView.setCenter(userLocation, animated: true)
494-
context.coordinator.isCenteredOnUser = true
495-
}
491+
// if existingCoordinates.count == 0 {
492+
// mapView.setCenter(userLocation, animated: true)
493+
// }
496494

497495
context.coordinator.isRegionSet = true
498496

GoInfoGame/GoInfoGame/UI/Map/MapView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ struct MapView: View {
6767

6868

6969
CustomMap(region: viewModel.region,
70-
userLocation: viewModel.userlocation,
7170
trackingMode: $trackingMode,
7271
items: $viewModel.items,
7372
selectedQuest: $viewModel.selectedQuest,

GoInfoGame/GoInfoGame/UI/Map/MapViewModel.swift

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)