- (IBAction)getdirections:(id)sender {
directionview=[[directionViewController alloc]initWithNibName:@"directionViewController" bundle:nil];
directionview.sourceplace=user.location;
[self.view addSubview:directionview.view];
}
我想将用户的位置存储在“sourceplace”中,这是另一个名为“NSString
”的视图控制器中的directionViewController
类型变量。
我从变量“user”中获取数据,我尝试NSLogging
用户,我可以看到它有“位置”键。
答案 0 :(得分:0)
在你的.h:
#import <CoreLocation/CoreLocation.h>
@interface yourController : UIViewController <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
NSString *str;
}
在你的.m:
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
您可以将位置转换为字符串,如下所示:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
CLLocation *location = [locations lastObject];
str=[[NSString alloc] initWithFormat:@" latitude:%f longitude:%f", location.coordinate.latitude, location.coordinate.longitude];
NSLog(@"%@",str);
}
之后
如果您的directionview.sourceplace也是NSString
:
directionview.sourceplace = str;