MKMapView zoom to users location on viewDidLoad?

前端 未结 10 1687
有刺的猬
有刺的猬 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:42

    Check out the method setUserTrackingMode of MKMapView. Probably the easiest way of tracking the user's location on a MKMapView is

    [self.mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
    

    That way you also don't need to be a MKMapViewDelegate. The possible modes are:

    MKUserTrackingModeNone = 0, // the user's location is not followed
    MKUserTrackingModeFollow, // the map follows the user's location
    MKUserTrackingModeFollowWithHeading, // the map follows the user's location and heading
    

提交回复
热议问题