【发布时间】:2011-08-26 09:03:19
【问题描述】:
我的目的是在加载视图时获取用户的经度/纬度,并将值存储在两个变量中以供以后计算。我不需要跟踪用户位置并对其进行更新,我只需要一次获取他/她的坐标。我的代码如下所示:
- (void)viewDidLoad {
[super viewDidLoad];
// locationManager update as location
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
// Configure the new event with information from the location
CLLocationCoordinate2D coordinate = [location coordinate];
float longitude=coordinate.longitude;
float latitude=coordinate.latitude;
NSLog(@"dLongitude : %f",longitude);
NSLog(@"dLatitude : %f", latitude);
}
在控制台中我不断收到这个:
dLongitude : 0.000000
dLatitude : 0.000000
你能帮帮我吗?
【问题讨论】:
-
你是在设备还是模拟器上测试?
-
您可以通过模拟器模拟您的位置,这并不重要。
标签: ios core-location