MKMapView zoom to users location on viewDidLoad?

前端 未结 10 1709
有刺的猬
有刺的猬 2021-01-30 16:40

I\'m trying to zoom a map into the user\'s current location once the view loads, but I\'m getting the error \"** * Terminating app due to uncaught exception \'NSInvalidA

10条回答
  •  面向向阳花
    2021-01-30 17:45

    As with Deepak's answer, except you could set the span more elegantly:

    - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
        MKCoordinateRegion mapRegion;   
        mapRegion.center = map.userLocation.coordinate;
        mapRegion.span = MKCoordinateSpanMake(0.2, 0.2);
        [map setRegion:mapRegion animated: YES];
    }
    

提交回复
热议问题