如果我想在地图上显示用户位置,同时记录用户的位置,最好在user location.location中添加一个观察者并记录位置,还是应该使用cllocationmanager来记录用户位置并使用mapview.show user location来显示用户的当前位置(蓝色指示器)?我想显示MapKit API支持的默认蓝色指示器。
此外,这里还有一个粗略的示例代码:
- (void)viewDidLoad {
...
locationManager = [[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = DISTANCE_FILTER_VALUE;
locationManager.delegate = self;
[locationManager startUpdatingLocation];
myMapView.showUserLocation = YES;
[myMapView addObserver:self forKeyPath:@"userLocation.location" options:0 context:nil];
...
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
// Record the location information
// ...
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSLog(@"%s begins.", __FUNCTION__);
// Make sure that the location returned has the desired accuracy
if (newLocation.horizontalAccuracy <= manager.desiredAccuracy)
return;
// Record the location information
// ...
}
在引擎盖下,我认为mkmapview还使用cllocationmanager获取用户的当前位置?所以,这会不会造成任何问题,因为我相信cllocationmanager和mapview都会尝试使用相同的位置服务?是否存在任何冲突,缺乏准确/必需或当前数据?