本文介绍了使用MKMapView时如何设置精度和距离滤镜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 当我使用 setShowsUserLocation 并使用 MKMapView 来跟踪用户位置时,如何设置精度和距离过滤器?我不是在谈论 CLLocationManager 。When i use setShowsUserLocation with MKMapView to track user location, how do I set the accuracy and distance filter? I am not talking about CLLocationManager.谢谢,推荐答案您无法控制内部 MKMapView 位置管理器(用于跟踪蓝点用户的位置管理器)的准确性),但您可以创建自己的并使用它来重新定位地图。这是一个食谱... You can't control the accuracy of the internal MKMapView location manager (the one used to track the user with the blue dot), but you can create your own and use it to recenter the map. Here is a recipe...在核心位置代表:- (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");} 设置核心位置 To setup core locationself.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 locationif ([CLLocationManager locationServicesEnabled]){ [self.locationManager startUpdatingLocation];} 使用我们的位置管理器重新定位地图 To recenter the map with our location manager- (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 Km)以上的例子中。Put that on the delegate. MKMapView doesn't have a distance or accuracy filter, only the CLLocationManager does. What MKMapView has is a region span around a point, in the example above 0.15 degrees (0.15*111 Km).该文档没有告诉 MKMapView 从哪里获取更新。我试过The documentation doesn't tell where MKMapView is getting its updates from. I tried- (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 添加您的委托。 and I'm getting different values on each. It looks as if MKMapView uses its own CLLocationManager, which means you can't set its accuracy. You can't add your delegate for the CLLocationManager of the MKMapView either. 我的印象是,设置精确度的唯一方法是将显示用户位置设置为NO并使用蓝点创建自定义注释,这意味着手动重新定位地图发布。您可以使用github项目图稿提取器从SDK获取蓝点图形。My impression is that the only way to set the accuracy is setting show user position to NO and create a custom annotation with a blue dot, which means recentering the map manually as posted. You can get the blue dot graphic from the SDK with the github project artwork-extractor.我不知道我是否遗漏了某些内容或 MKMapView 只是很糟糕。I don't know if I'm missing something or this part of MKMapView just sucks. 这篇关于使用MKMapView时如何设置精度和距离滤镜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-10 10:12