iphone - CLLocationManager startUpdatingLocation 不工作

标签 iphone ios mkmapview zooming cllocationmanager

所以现在我至少得到了以下代码的回调......

- (void)viewDidLoad {

[super viewDidLoad];
mapView=[[MKMapView alloc] initWithFrame:self.view.frame];
//mapView.showsUserLocation=TRUE;
mapView.delegate=self;
[self.view insertSubview:mapView atIndex:0];

NSLog(@"locationServicesEnabled: %@", [CLLocationManager locationServicesEnabled] ? @"YES":@"NO");
    CLLocationManager *newLocationManager = [[CLLocationManager alloc] init];
    [newLocationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    [newLocationManager setDistanceFilter:kCLDistanceFilterNone];
    [self setLocationManager:newLocationManager];


[[self locationManager] setDelegate:self];
[[self locationManager] startUpdatingLocation];
NSLog(@"Started updating Location");

}


- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

NSLog(@"Did update to location");
mStoreLocationButton.hidden=FALSE;
location=newLocation.coordinate;

MKCoordinateRegion region;
region.center=location;
MKCoordinateSpan span;
span.latitudeDelta=0.01;
span.longitudeDelta=0.01;
region.span=span;


[mapView setRegion:region animated:TRUE];


}

我可以在第二种方法中设置断点,并且 NSLog 正在报告持续的位置更新,但由于某种原因,带跨度的缩放不起作用。知道为什么吗?它有我的坐标和一切。有点摸不着头脑。

最佳答案

将 CLLocationManager 分配给您类(class)的一个(强)属性。 (顺便说一句,我假设您使用的是 ARC。)现在 CLLocationManager 不会在 viewDidLoad 方法结束后继续存在,因此它也不会调用您的委托(delegate)方法。

关于iphone - CLLocationManager startUpdatingLocation 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11697730/

相关文章:

iphone - objc_msg发送崩溃:如何找到位置?

iphone - MapView注解indexPath?

iphone - UITableView 滚动时重复单元格

ios - 在 iOS 9 中邀请 Facebook 好友

ios - .hash 给出 EXC_BREAKPOINT (code=EXC_ARM_BREAKBOINT

ios - 添加新叠加层时,MKMapView 叠加层重绘(闪烁)。 MKPolyLines 呈锯齿状

iphone - 将 TextField 添加到 UIAlertView

ios - 如何将方法调用延迟 1 秒?

iOS Segue - 何时实例化 viewControllers

iphone - 选择国家时在国家(Mapkit)上绘制颜色