我实际上正在设计一个简单的应用程序来利用核心位置来获取位置详细信息,同时显示纬度和经度。但是当我运行它时,我收到如下错误消息:
由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类与键 forLatitude 的键值编码不兼容。”
我也合成了属性。我仍然不知道为什么它会抛出错误的确切原因!
rajViewController.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface rajViewController : UIViewController <CLLocationManagerDelegate>
@property (weak, nonatomic) IBOutlet UILabel *latitudeLabel;
@property (weak, nonatomic) IBOutlet UILabel *longitudeLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
- (IBAction)getCurrentLocation:(id)sender;
@end
rajViewController.m
@interface rajViewController (){
CLLocationManager *locationManager;
CLGeocoder *geo;
CLPlacemark *placemark;
}
@end
@implementation rajViewController
//@synthesize placemark;
@synthesize latitudeLabel;
@synthesize longitudeLabel;
.
.
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *newPlace = [[CLLocation alloc]init];
newPlace = [locations lastObject];
NSLog(@"the latitude is : %f",newPlace.coordinate.latitude);
if (newPlace!=nil){
self.latitudeLabel.text = [NSString stringWithFormat:@"%f", newPlace.coordinate.latitude];
self.longitudeLabel.text = [NSString stringWithFormat:@"%f",newPlace.coordinate.longitude];
}
}
任何帮助将非常感激。
谢谢和问候,拉吉。