【发布时间】:2014-07-25 17:53:45
【问题描述】:
我正在创建一个使用核心位置的应用,这是我的代码:
.h:
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface ViewController : UIViewController
<CLLocationManagerDelegate>
@property(strong,nonatomic) CLLocationManager *manager;
@end
.m:
#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
@interface ViewController ()
@end
@implementation ViewController
@synthesize manager;
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidLoad
{
[super viewDidLoad];
if (!self.manager)
{
self.manager=[CLLocationManager new];
}
self.manager.delegate = self;
self.manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
[self.manager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation * currentLocation = (CLLocation *)[locations lastObject];
NSLog(@"Location: %@", currentLocation);
if (currentLocation != nil)
{
NSLog([NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude]);
NSLog([NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude]);
}
}
@end
问题是 didUpdateToLocation 没有被调用。
我尝试在其中放置一个断点,但什么也没发生。
【问题讨论】:
标签: ios location core-location cllocationmanager