- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSDateFormatter * formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
NSString *latitude = [NSString stringWithFormat:@"%f", newLocation.coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", newLocation.coordinate.longitude];
NSString *stringFromDate = [formatter stringFromDate:newLocation.timestamp];
resultsLabel.text = [NSString stringWithFormat:@"(%@) %@ Location %.06f %.06f %@", ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) ? @"bg" : @"fg", resultsLabel.tag == 0 ? @"gps:" : @"sig" , newLocation.coordinate.latitude, newLocation.coordinate.longitude, [formatter stringFromDate:newLocation.timestamp]];
NSLog(@"%@", resultsLabel.text);
LocationTestAppDelegate * appDelegate = (LocationTestAppDelegate *)[UIApplication sharedApplication].delegate;
[appDelegate log:resultsLabel.text];
}
但我把它作为输出。
(null)
上 :
NSLog(@"%@", resultsLabel.text);
有谁知道我做错了什么?
- (id) initWithLabel:(UILabel*)label
{
resultsLabel = label;
return [super init];
}
在我的委托中,我在这里设置了 resultLabel:
- (void) log:(NSString*)msg
{
NSDateFormatter * formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setTimeStyle:NSDateFormatterMediumStyle];
NSString * logMessage = [NSString stringWithFormat:@"%@ %@", [formatter stringFromDate:[NSDate date]], msg];
NSString * fileName = [self locationPath];
FILE * f = fopen([fileName UTF8String], "at");
fprintf(f, "%s\n", [logMessage UTF8String]);
fclose (f);}
编辑
我删除了 GPS 功能。
有谁知道正确的 NSLog 会在新位置。经纬度时间戳?
编辑 2
我在这里设置了结果标签:
@interface LocationDelegate : NSObject <CLLocationManagerDelegate>
{
UILabel * resultsLabel;
NSString * _phonenumber;
}
- (id) initWithLabel:(UILabel*)label;
//-(id)initWithDictionary:(NSDictionary *)dict;
//-(id)initWithName:(NSString *)aName;
//-(NSDictionary *)toDictionary;
@property (nonatomic , retain) NSString *phonenumber;