在您的 .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;