Skip to content

Commit c14b81d

Browse files
author
Achyut Kumar M
committed
fix user location after switching
1 parent 80dd31a commit c14b81d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

GoInfoGame/GoInfoGame/UI/Map/CustomMap.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,20 @@ struct CustomMap: UIViewRepresentable {
162162

163163
// Helper method to update the region
164164
func updateUserRegion(_ mapView: MKMapView) {
165-
// Update the region only if it hasn't been set yet
166-
if self.parent.isPresented {
167-
return
168-
} else if !isRegionSet {
165+
guard !parent.isPresented else { return }
166+
167+
let center = parent.region.center
168+
guard CLLocationCoordinate2DIsValid(center),
169+
!(center.latitude == 0 && center.longitude == 0) else { return }
170+
171+
if parent.selectedAnnotations.isEmpty && !isRegionSet {
169172
mapView.setRegion(parent.region, animated: true)
170173
isRegionSet = true
171174
}
175+
172176
}
177+
178+
173179

174180

175181
// To keep the selected annotation visible at the top
@@ -229,6 +235,9 @@ struct CustomMap: UIViewRepresentable {
229235
// Customizes the view for each annotation
230236
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
231237
self.mapView = mapView
238+
if annotation is MKUserLocation {
239+
return nil
240+
}
232241
if let clusterAnnotation = annotation as? MKClusterAnnotation {
233242
let identifier = "cluster"
234243
var clusterView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? MKMarkerAnnotationView

0 commit comments

Comments
 (0)