Skip to content

Commit 99c5f1e

Browse files
committed
assign region
1 parent ba1593e commit 99c5f1e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

GoInfoGame/GoInfoGame/UI/Map/MapViewModel.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class MapViewModel: ObservableObject {
1515
let locationManagerDelegate = LocationManagerDelegate()
1616

1717
var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 37.3318, longitude: -122.0312), span: MKCoordinateSpan(latitudeDelta: 0.0004 , longitudeDelta: 0.0004 ))
18+
let viewSpanDelta = 0.0004 // Delta lat/lng to show to the user
1819

1920

2021
@Published var items: [DisplayUnitWithCoordinate] = []
@@ -39,6 +40,10 @@ class MapViewModel: ObservableObject {
3940
func fetchOSMDataFor(currentLocation: CLLocation) {
4041
isLoading = true
4142
let bBox = boundingBoxAroundLocation(location: currentLocation, distance: dataSpanDistance)
43+
self.region = MKCoordinateRegion(center: currentLocation.coordinate, span: MKCoordinateSpan(
44+
latitudeDelta: viewSpanDelta,
45+
longitudeDelta: viewSpanDelta
46+
))
4247
AppQuestManager.shared.fetchData(fromBBOx: bBox) { [weak self] in
4348
guard let self = self else { return }
4449
self.items = AppQuestManager.shared.fetchQuestsFromDB()
@@ -55,6 +60,7 @@ class MapViewModel: ObservableObject {
5560
let minLon = center.longitude - span.longitudeDelta / 2
5661
let maxLon = center.longitude + span.longitudeDelta / 2
5762

63+
5864
return BBox(minLat: minLat, maxLat: maxLat, minLon: minLon, maxLon: maxLon)
5965
}
6066
}

0 commit comments

Comments
 (0)