1
- (IBAction)getdirections:(id)sender {
    directionview=[[directionViewController alloc]initWithNibName:@"directionViewController" bundle:nil];
    directionview.sourceplace=user.location;
    [self.view addSubview:directionview.view];
}

我想将用户的位置存储在“sourceplace”中,这是NSString另一个名为“”的视图控制器中的类型变量directionViewController。我正在从变量“用户”中获取数据,我尝试了NSLogging用户,我可以看到它具有“位置”键。

4

1 回答 1

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.sourceplaceNSString也是:

directionview.sourceplace = str;
于 2013-09-20T16:59:29.857 回答