我想让用户获得当前位置,我在stackoverflow中找到了解决方案:How to find your current location with 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);
}