CLLocationManager 没有给我我的位置
这是我的代码
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 时,我的 long 和 lat 是 0.000000。另外,我正在使用模拟器,但我希望我的经度和纬度在我当前位置所在的位置处于无限循环。有人有任何见解吗?
Here is my code
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];
When I do my NSLog my long and lat are 0.000000. Also, I am using the simulator but I expected my long and lat to be at infinite loop where my current location is. Does anyone have any insight?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
删除 startUpdatingLocation 之后的所有内容,并在类中实现此方法,该方法是 CLLocationManagerDelegate 协议的一部分:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// 此处使用 newLocation
。
另外,在实际设备上进行测试
Remove everything after startUpdatingLocation and implement this method in your class, which is part of the CLLocationManagerDelegate protocol:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// use newLocation here
}
Also, test on an actual device.