MKMapView zoom to users location on viewDidLoad?

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

    ......

    MKCoordinateRegion region =mapView.region;
    
    region.center.latitude = currentLocation.latitude ;
    region.center.longitude = currentLocation.longitude;
    region.span.longitudeDelta /= 1000.0;
    region.span.latitudeDelta /= 1000.0;
    
    [mapView setRegion:region animated:YES];
    [mapView regionThatFits:region];
    

提交回复
热议问题