Go to/zoom to current location function (MapKit) Go to/zoom to current location function (MapKit) xcode xcode

Go to/zoom to current location function (MapKit)


You need to set the center of your map to the current location on tap of that button. Say, like this:

- (IBAction)showCurrentLocation {            [mapView setCenterCoordinate:mapView.userLocation.location.coordinate animated:YES];}


you can also try:

mapView.userTrackingMode=YES;mapView.userTrackingMode=NO;


You can link this IBAction to your UIButton,it's going to move the map on the current location and zoom on it.

@IBOutlet weak var mapView: MKMapView!@IBAction func zoomToUserCurrentLocation(sender: AnyObject) {    if self.mapView != nil {        self.mapView.setRegion(MKCoordinateRegionMake(            self.mapView.userLocation.coordinate,             MKCoordinateSpanMake(0.1, 0.1)        ), animated: true)    }}

MKCoordinateSpan defines the area spanned by a map region, smaller these values are, closer you zoom on the map.