Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ios-locationManager返回0.0000_Ios_Objective C_Cllocationmanager - Fatal编程技术网

ios-locationManager返回0.0000

ios-locationManager返回0.0000,ios,objective-c,cllocationmanager,Ios,Objective C,Cllocationmanager,CLLocationManager是异步的。当底部的代码执行时,它将没有机会获得位置。您应该从CLLocationManagerDelegate实现方法,例如–locationManager:didUpdateLocations:: - (void)viewDidLoad { [super viewDidLoad]; NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConf

CLLocationManager
是异步的。当底部的代码执行时,它将没有机会获得位置。您应该从
CLLocationManagerDelegate
实现方法,例如
–locationManager:didUpdateLocations:

- (void)viewDidLoad
{
    [super viewDidLoad];
     NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
     config.URLCache = [[NSURLCache alloc] initWithMemoryCapacity:2 * 1024 * 1024
                                                    diskCapacity:10 * 1024 * 1024
                                                        diskPath:@"MarkerData"];
    self.markerSession = [NSURLSession sessionWithConfiguration:config];


    locationManager = [[CLLocationManager alloc] init];
    NSLog(@"locationServicesEnabled: %@", [CLLocationManager locationServicesEnabled] ? @"YES":@"NO");

    CLLocationManager *lm = [[CLLocationManager alloc] init];
    lm.delegate = self;
    lm.desiredAccuracy = kCLLocationAccuracyBest;
    lm.distanceFilter = kCLDistanceFilterNone;
    [lm startUpdatingLocation];
    //[lm stopUpdatingLocation];

    CLLocation *location = [lm location];

    CLLocationCoordinate2D coord;
    coord.longitude = location.coordinate.longitude;
    NSString *ss= [NSString stringWithFormat:@"%.8f",coord.longitude ];

    coord.latitude = location.coordinate.latitude;
    NSString *aa= [NSString stringWithFormat:@"%.8f",coord.latitude ];
    NSLog(@"oooooooo2");
    NSLog(ss);
    NSLog(aa);
    NSLog(@"kkkkkkkkk2");

}
@接口MyClass()
@结束
@MyClass的实现
-(无效)viewDidLoad
{
...
CLLocationManager*lm=[[CLLocationManager alloc]init];
lm.代表=自我;
...
}
-(无效)locationManager:(CLLocationManager*)locationManager didUpdateLocations:(NSArray*)位置
{
CLLocation*location=[locationManager位置];
CLLocationCoordinate2D coord;
坐标经度=位置坐标经度;
等
}
@结束
如果你对这类事情感兴趣的话,有人也发了一封信

@interface MyClass() <CLLocationManagerDelegate>

@end

@implementation MyClass

- (void)viewDidLoad
{
    ...
    CLLocationManager *lm = [[CLLocationManager alloc] init];
    lm.delegate = self;
    ...
}

- (void)locationManager:(CLLocationManager *)locationManager didUpdateLocations:(NSArray *)locations
{
    CLLocation *location = [locationManager location];
    CLLocationCoordinate2D coord;
    coord.longitude = location.coordinate.longitude;
    etc...
}

@end