所以现在我至少会收到以下代码的回调...

- (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分配给您类的(strong)属性。 (我假设您使用的是ARC BTW。)现在,CLLocationManager并没有超出viewDidLoad方法的末尾,因此也无法调用您的委托(delegate)方法。

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

10-12 14:44