我是 iOS 编程新手,并试图获取我当前的位置。我的主要应用程序代表是这样的,
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@class AWSViewController;
@interface AWSAppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) AWSViewController *viewController;
@property (strong, nonatomic) UINavigationController *navController;
@property (strong, nonatomic) NSMutableArray *cities;
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;
@end
在实现中,我有这两种方法,我从(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
我可以在控制台上看到“开始获取位置”字样,之后我看不到任何其他内容。
-(void)getCurrentLocation {
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
locationManager.distanceFilter = 500;
[locationManager startUpdatingLocation];
NSLog(@"Started to get locations");
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
CLLocation *location = [locations lastObject];
NSLog(@"Got Location");
NSLog(@"latitude %+.6f, longitude %+.6f\n", location.coordinate.latitude, location.coordinate.longitude);
}
我在这里做错了什么?谢谢