MKMapView tiles not loaded with zoom

两盒软妹~` 提交于 2019-12-07 03:28:57

问题


I've got an issue. I'm using a MKMapView for displaying some annotations. I initialize a map view with default zoom. And it displays some map.

but when i try zooming, tiles not loaded, and map becomes empty. Like this.

I create my Map View via interface builder.

@property (nonatomic, weak) IBOutlet MKMapView* mapView;

What am I doing wrong? Is there any mandatory methods for implementation, that affect on this functional? And yes, there is an internet connection on my device.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/26355425/mkmapview-tiles-not-loaded-with-zoom

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