【发布时间】:2012-01-17 23:40:07
【问题描述】:
我要求我的 MapView 显示用户的当前位置,我使用 startUpdatingLocation 的委托从 CLLocationManager 获取它,并且我还向 MapView 添加了一些注释,但问题是当在地图中滚动以显示一些注释时地图返回当前用户的注解
- (void)viewDidLoad
{
[super viewDidLoad];
// Get the location if the user
_locationManager = [[CLLocationManager alloc] init];
if ([CLLocationManager locationServicesEnabled])
{
_locationManager.delegate = self;
[_locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[_locationManager startUpdatingLocation];
}
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// set the map view to the current location
MKCoordinateSpan span;
span.latitudeDelta = 0.01;
span.longitudeDelta = 0.05;
MKCoordinateRegion region;
region.span = span;
region.center = _locationManager.location.coordinate;
[self.mapView setRegion:region animated:YES];
}
【问题讨论】:
标签: iphone cocoa-touch ipad mkmapview cllocationmanager