CLLocationManager 没有给我我的位置

发布于 2024-11-04 16:12:45 字数 718 浏览 0 评论 0原文

这是我的代码

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

裸钻 2024-11-11 16:12:45

删除 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文