【发布时间】:2013-05-12 19:46:22
【问题描述】:
所以我一直在尝试学习如何在 Objective-C 中实现 iPhone 定位。目前我有几个文件:
locator.h
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@interface locator : NSObject
- (void)locationManager:(CLLocationManager *)manager;
@end
locator.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
viewController.h
#import <UIKit/UIKit.h>
#import "locator.h"
@interface ViewController : UIViewController
@end
viewController.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 个重大错误。
【问题讨论】:
-
我不明白您为什么要实现定位器类(无论如何您都不使用它)。并且您必须声明您的 viewController 符合 CLLocationManagerDelegate,即:@interface ViewController : UIViewController
标签: iphone ios objective-c location