我的目的是在加载视图时获取用户的经度/纬度,并将值存储在两个变量中以供以后计算.我不需要跟踪用户的位置并更新它,我只需要一次他/她的坐标.我的代码如下所示:
- (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
你能帮我吗