MKMapView tiles not loaded with zoom

青春壹個敷衍的年華 提交于 2019-12-05 08:28:57

Generally this can happens due to internet connection. If you have slow internet connection than it takes time to load map tiles.

About methods i recommended to override below method.

Override MKMapView delegate method -

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated

Will call every time you zoom in/out and load map tiles.

PS - provide MKMapViewDelegate to your view controller.

Eshwar Chaitanya

I had the same loading problem till I got the problem working by googling!

Note: Effective ios 8 & later, we need to add a value NSLocationWhenInUseUsageDescription in Info.plist file with our own value as description. This is because showsUserLocation property of **MKMapView** doesn't work straight away. More info here !!!!

//This should be declared in .h file
@property(nonatomic, strong) CLLocationManager *locationManager;


- (void)viewDidLoad {
    self.mapView.showsUserLocation = YES;
    self.mapView.delegate = self;
    self.locationManager.delegate = self;
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.distanceFilter = kCLDistanceFilterNone;
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;

#ifdef __IPHONE_8_0
    if(IS_OS_8_OR_LATER) {
        [self.locationManager requestWhenInUseAuthorization];
    }
#endif
    [self.locationManager startUpdatingLocation];
    self.locationManager.distanceFilter = kCLDistanceFilterNone;
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
}

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
    if (status == kCLAuthorizationStatusAuthorizedAlways || status == kCLAuthorizationStatusAuthorizedWhenInUse) {
        self.mapView.showsUserLocation = YES;
    }
}

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    MKCoordinateRegion region;
    region.center = self.locationView.userLocation.coordinate;

    MKCoordinateSpan span;
    span.latitudeDelta  = 0.015; ->Adjust this value to zoom as per your requirement
    span.longitudeDelta = 0.015;
    region.span = span;

    [self.mapView setRegion:region animated:YES];
}

I firmly believe this will yield the expected result without fail, i.e. MKMapView zoom to the current user location.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!