CLLocationManager没有给我我的位置

时间:2011-04-29 19:15:15

标签: iphone mapkit

这是我的代码

CLLocationManager* locationManager = [[[CLLocationManager alloc]init]autorelease];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];


NSLog(@"Latitude :%f",locationManager.location.coordinate.latitude);

CLLocation* currentLocation = [locationManager location];
_drivingReverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:[currentLocation coordinate]];
[_drivingReverseGeocoder setDelegate:self];
[_drivingReverseGeocoder start];

当我执行我的NSLog时,我的长和纬度为0.000000。此外,我正在使用模拟器,但我希望我的长和lat在无限循环,我的当前位置。有没有人有任何见解?

1 个答案:

答案 0 :(得分:2)

在startUpdatingLocation之后删除所有内容,并在您的类中实现此方法,该方法是CLLocationManagerDelegate协议的一部分:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {     //在这里使用newLocation }

另外,在实际设备上进行测试。