本文介绍了纬度和经度未检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

针对iOS9的更新:我是iOS的新手,尝试使用CoreLocation返回纬度和经度值。以下代码从不执行日志输出

UPDATED for iOS9: I am new to iOS, experimenting with CoreLocation to return latitude and longitude values. The following code never executes the log output

 -(void)viewWillAppear:(BOOL)animated{

manager = [[CLLocationManager alloc]init];

manager.delegate = self;
manager.desiredAccuracy = kCLLocationAccuracyBest;

[manager startUpdatingLocation];
}

这是我的didUpdateToLocation函数,从未达到

Here is my didUpdateToLocation function with is never reached

- (void)locationManager:(CLLocationManager *)manager
 didUpdateLocations:(NSArray<CLLocation *> *)locations{

NSLog(@"Location: %@", locations);
CLLocation *currentLocation = locations.lastObject;

if (currentLocation != nil) {
    float latitude = currentLocation.coordinate.latitude;

    float longitude = currentLocation.coordinate.longitude;

    NSLog(@"dLongitude : %f", longitude);
    NSLog(@"dLatitude : %f", latitude);
}

else{ NSLog(@"ERROR");
    }

}

推荐答案

1。首先,您应该使用应该使用实际设备而不是模拟器

1.first of all, you should use you should use a actual device instead of a simulator

2.implement CLLocationManagerDelegate在界面,例如

2.implement CLLocationManagerDelegate in the interface,like

@interface XXXXX () <CLLocationManagerDelegate>

3。

locationManager = [[CLLocationManager alloc] init];

添加

locationManager.delegate = self;

4。实现委托方法

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
{
    for (CLLocation *location in locations) {
        //you can get locations here

    }
}

这篇关于纬度和经度未检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-12 22:18