좌표에 따라 정확한 현재 위치를 얻으려고합니다. 내 viewController
에 CLLocationManager
을 구현했습니다. myLocation
입니다. 제 문제는 처음으로 좌표를 얻지는 않을 것이지만 다시 접근하면 좌표가 생깁니다. 이 문제가 왜 처음으로 나타나지 않는지 이해할 수 없습니다. 또한 NSTimer
을 stoplocation
에게 줄려고했으나 처음으로 결과를 얻지 못하고 처음으로 (null) 값을 얻었을 때 좌표를 얻지 못했습니다.좌표 얻기 CLLocationManager IOS
내 코드 : 당신이 CLLocationManager
아직 최초의 위치를 검색 할 수있는 충분한 시간이 없었 때문에 viewWillAppear:
에서 그들을 인쇄하려고 할 때
#import <UIKit/UIKit.h>
#import <Corelocation/CoreLocation.h>
@interface myLocation : UITableViewController<CLLocationManagerDelegate>
@property (strong, nonatomic) CLLocationManager *locationManager;
@end
@interface myLocation() {
CLLocationManager* _locationManager;
NSString * _lat;
NSString * _lng;
}
@end
@implementation myLocation
- (void)viewDidLoad
{
[super viewDidLoad];
_locationManager = [[CLLocationManager alloc] init];
_locationManager.distanceFilter = kCLDistanceFilterNone;
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
[_locationManager requestWhenInUseAuthorization];
[_locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
CLLocation *location = [locations lastObject];
[_locationManager stopUpdatingLocation];
_lat =[NSString stringWithFormat:@"%f",location.coordinate.latitude];
_lng =[NSString stringWithFormat:@"%f",location.coordinate.longitude];
}
- (void)viewWillAppear:(BOOL) animated
{
NSLOG(@"%@",_lat);
NSLOG(@"%@",_lng);
}
오, 왜 좌표가 viewWillAppear에 인쇄되지 않는 것입니까? –
네, 처음으로. @LyndseyScott – developer