Zoom in on User Location- Swift

You have to try this. It will zooming map.

let span = MKCoordinateSpanMake(0.050, 0.050)
let region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 23.0225, longitude: 72.5714), span: span)
mapView.setRegion(region, animated: true)`

I would try something like this:

    let latitude:CLLocationDegrees = //insert latitutde

    let longitude:CLLocationDegrees = //insert longitude

    let latDelta:CLLocationDegrees = 0.05

    let lonDelta:CLLocationDegrees = 0.05

    let span = MKCoordinateSpanMake(latDelta, lonDelta)

    let location = CLLocationCoordinate2DMake(latitude, longitude)

    let region = MKCoordinateRegionMake(location, span)

    mapView.setRegion(region, animated: false)

I saw you said you tried setting a region. Maybe try doing it this way.


On most apps, a 'current location' button is implemented. A simple way to do it is like this:

@IBAction func myLocationButtonTapped(_ sender: Any) {

    mapView.showsUserLocation = true
    mapView.setUserTrackingMode(.follow, animated: true)

}

Once the user pans or zooms the map, the tracking will stop. So it's good enough for me.

Tags:

Ios

Swift

Mapkit