Deven Nazare
Deven Nazare

Reputation: 518

Mapview camera zoom not getting set for the current location

I want to set a proper zoom level for the user's current location using the MapKit. I tried solutions from the stack but it's not working for me. What can I try next?

locationManager.requestWhenInUseAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.distanceFilter = kCLDistanceFilterNone
locationManager.startUpdatingLocation()
mapView.showsUserLocation = true

for point in points {
    let annotation = MKPointAnnotation()
    
    annotation.coordinate = CLLocationCoordinate2D(latitude: point["latitude"] as! Double, longitude: point["longitude"] as! Double)
    mapView.addAnnotation(annotation)
}

let region = MKCoordinateRegion(center: annotation.coordinate, latitudinalMeters: CLLocationDistance(exactly:9000)!, longitudinalMeters: CLLocationDistance(exactly: 9000)!)
mapView.setRegion(mapView.regionThatFits(region), animated: true)

I tried this code but it's not getting zoomed properly at user's location.

Upvotes: 1

Views: 67

Answers (0)

Related Questions