【问题标题】:MKMapView tiles not loaded with zoomMKMapView 瓦片未加载缩放
【发布时间】:2014-12-08 22:17:55
【问题描述】:

我有一个问题。我使用MKMapView 来显示一些注释。我使用默认缩放初始化地图视图。它会显示一些地图。

但是当我尝试缩放时,没有加载图块,并且地图变为空。像这样。

我通过界面生成器创建我的地图视图。

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

我做错了什么?是否有任何强制实施方法会影响此功能?是的,我的设备上有互联网连接。

【问题讨论】:

  • 你找到解决办法了吗?

标签: ios objective-c iphone mkmapview mapkit


【解决方案1】:

这通常是由于互联网连接而发生的。如果您的互联网连接速度较慢,则加载地图图块需要时间。

关于我建议覆盖以下方法的方法。

覆盖MKMapView委托方法-

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

每次放大/缩小和加载地图图块时都会调用。

PS - 将MKMapViewDelegate 提供给您的视图控制器。

【讨论】:

  • 但是互联网连接可用,并且缩放后磁贴从未加载。我不明白为什么。
  • 发布你的代码,你如何创建`MKMapView,你正在使用哪些委托。
  • 我不知道为什么,但它适用于其他设备。使用相同的 iOS 7。我使用界面生成器创建它并在 IB 中设置委托。
【解决方案2】:

在我通过谷歌搜索解决问题之前,我遇到了同样的加载问题!

注意:从 ios 8 及更高版本开始,我们需要在 Info.plist 文件中添加一个值 NSLocationWhenInUseUsageDescription 并使用我们自己的值作为描述。这是因为**MKMapView**showsUserLocation 属性不能立即工作。更多信息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];
}

我坚信这一定会产生预期的结果,即 MKMapView 缩放到当前用户位置。

【讨论】:

  • 仅当您想显示用户的位置时才需要使用位置权限。您不需要用户位置权限即可显示地图。
猜你喜欢
  • 2019-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-13
  • 1970-01-01
相关资源
最近更新 更多