我想获取用户当前位置,我在 stackoverflow 中找到了该解决方案:如何使用 CoreLocation 找到您的当前位置。但尽管有这个解决方案,我还是在 Nslog 上收到了这条消息:
2013-05-07 23:57:56.962 XXXXX[1951:c07] Latitude:(null),Longitude:(null)
这是我所做的:
在头文件中:
#import <CoreLocation/CoreLocation.h>
NSString *UsersCurrentLatitude;
NSString *UsersCurrentLongitude;
CLLocationManager *locationManager;
在实施中:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UsersCurrentLongitude:[NSString stringWithFormat:@"%f", locationManager.location.coordinate.longitude];
UsersCurrentLatitude:[NSString stringWithFormat:@"%f", locationManager.location.coordinate.latitude];
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
NSLog(@"Latitude:%@,Longitude:%@",UsersCurrentLatitude,UsersCurrentLongitude);
}