大佬教程收集整理的这篇文章主要介绍了iphone – 如何设置精度和距离过滤器使用MKMapView时,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
处理核心位置权限
在核心位置代表:
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied){ NSLog(@"User has denied location services"); } else { NSLog(@"Location manager did fail with error: %@",error.localizedFailureReason); } }
设置位置管理器之前:
if (![CLLocationManager locationServicesEnabled]){ NSLog(@"location services are disabled"]; return; } if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied){ NSLog(@"location services are blocked by the user"); return; } if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized){ NSLog(@"location services are enabled"); } if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined){ NSLog(@"about to show a dialog requesting permission"); }
设置核心位置
self.locationManager = [CLLocationManager new]; self.locationManager.purpose = @"Tracking your movements on the map."; self.locationManager.delegate = self; /* Pinpoint our location with the following accuracy: * * kCLLocationAccuracyBestForNavigation highest + sensor data * kCLLocationAccuracyBest highest * kCLLocationAccuracyNearestTenMeters 10 meters * kCLLocationAccuracyHundredMeters 100 meters * kCLLocationAccuracyKilometer 1000 meters * kCLLocationAccuracyThreeKilometers 3000 meters */ self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; /* Notify changes when device has moved x meters. * Default value is kCLDistanceFilterNone: all movements are reported. */ self.locationManager.distanceFilter = 10.0f; /* Notify heading changes when heading is > 5. * Default value is kCLheadingFilterNone: all movements are reported. */ self.locationManager.headingFilter = 5; // update location if ([CLLocationManager locationServicesEnabled]){ [self.locationManager startUpdatingLocation]; }
使用我们的位置管理器重新显示地图
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { MKCoordinateRegion region = { { 0.0f,0.0f },{ 0.0f,0.0f } }; region.center = newLocation.coordinate; region.span.longitudeDelta = 0.15f; region.span.latitudeDelta = 0.15f; [self.mapView setRegion:region animated:YES]; }
把它放在代理上。 MKMapView没有距离或精度过滤器,只有CLLocationManager。 MKMapView有一个区域跨越一个点,在上面的例子中,0.15度(0.15 * 111公里)。
事情,我试过,没有工作
该文档不知道哪里的MKMapView获取其更新。我试过了
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { NSLog(@"newLocation %@",newLocation.timestamp); NSLog(@"last map location %@",[NSString stringWithFormat:@"%@",[[[self.mapView userLocation] location] timestamp]]); }
我每个都得到不同的值。看起来像MKMapView使用它自己的CLLocationManager,这意味着你不能设置其准确性。您不能为MKMapView的CLLocationManager添加您的委托。
我的印象是,唯一的设置准确性的方法是将用户位置设置为NO,并创建一个带有蓝点的自定义注释,这意味着手动重新绘制地图。您可以使用github项目图稿提取器从SDK获取蓝点图形。
我不知道我是否缺少某些东西,或者这部分MKMapView只是吮吸了。
以上是大佬教程为你收集整理的iphone – 如何设置精度和距离过滤器使用MKMapView时全部内容,希望文章能够帮你解决iphone – 如何设置精度和距离过滤器使用MKMapView时所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。