我的目的是在加載視圖時獲取用戶的經度/緯度,並將值存儲在兩個變量中供以後計算。我不需要跟蹤用戶位置並更新它,我只需要獲得他/她的座標一次。我的代碼如下所示:獲取用戶的經度/緯度當viewDidLoad
- (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
能否請你幫我嗎?
您是在設備上還是在模擬器上測試? – Eiko 2011-05-16 11:31:08
模擬器:) – Luca 2011-05-16 12:45:53
你可以通過模擬器模擬你的位置,它並不重要。 – 2015-05-22 14:14:25