所以我一直在尝试学习如何在 Objective-C 中实现 iPhone 定位。目前我有几个文件:
定位器.h
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@interface locator : NSObject
- (void)locationManager:(CLLocationManager *)manager;
@end
定位器.m
#import "locator.h"
#import <CoreLocation/CoreLocation.h>
@implementation locator
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
CLLocationDegrees latitude = newLocation.coordinate.latitude;
CLLocationDegrees longitude = newLocation.coordinate.longitude;
}
@end
视图控制器.h
#import <UIKit/UIKit.h>
#import "locator.h"
@interface ViewController : UIViewController
@end
视图控制器.m
#import "ViewController.h"
#import "locator.h"
#import <CoreLocation/CoreLocation.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self; // Set your controller as a <CLLocationManagerDelegate>.
[locationManager startUpdatingLocation];
[super viewDidLoad];
}
@end
我确定我有时犯了一个重大错误,但我很困惑,并不真正理解它是什么。尝试运行此程序时出现 2 个重大错误。