2013-06-30 3 views
0

CLLocationManager 등을 사용하여 현재 위치를 얻는 Objective-C로 작성된 간단한 앱이 있습니다. 코드는 iPhone 6.1 시뮬레이터에서 제대로 작동하지만 작동하지 않습니다 내 실제 iPod touch에서. 아이팟 터치 제 3 세대는 iOS5.1을 실행 중이며 사용자가 위치 서비스를 사용하도록 요청하지만 업데이트되지는 않습니다. 여러분이 물어 본다면 코드를 게시 할 수 있지만, 다소 간단한 수정이 될만한 현저한 호환성 문제가있을 것이라고 생각했습니다. 도움이 될 것입니다. 감사합니다. ~ CarpetfizziOS5.1의 위치 서비스가 작동하지 않음

ViewController.h

#import <UIKit/UIKit.h> 
#import <CoreLocation/CoreLocation.h> 

@interface ViewController : UIViewController <CLLocationManagerDelegate> 
{ 
    CLLocationManager* locationManager; 
} 

@property (weak, nonatomic) IBOutlet UILabel *labelLong; 
@property (weak, nonatomic) IBOutlet UILabel *labelLat; 
-(IBAction)updateLocaitonButtonAction:(id)sender; 
@end 

ViewController.m

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 
@synthesize labelLong,labelLat; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    locationManager = [[CLLocationManager alloc]init]; 
    locationManager.delegate = self; 
    locationManager.distanceFilter = kCLDistanceFilterNone; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    [locationManager startUpdatingLocation]; 
} 

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 
{ 
    CLLocation *location = [locations lastObject]; 
    NSLog(@"%f,%f",location.coordinate.latitude,location.coordinate.longitude); 
    self.labelLong.text = [NSString stringWithFormat:@"%f",location.coordinate.longitude]; 
    self.labelLat.text = [NSString stringWithFormat:@"%f",location.coordinate.latitude]; 
    [locationManager stopUpdatingLocation]; 
} 

-(IBAction)updateLocaitonButtonAction:(id)sender 
{ 
    [locationManager startUpdatingLocation]; 
} 


- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 
+0

를 사용할 수 있습니까? iPod touch는 Wi-Fi 신호를 기반으로 위치하므로 정확한 정보는 아닙니다. –

+0

그것은 실제로 오른쪽 거리를 얻는다. 내가 위도와 경도를 얻을 수없는 이유는 무엇입니까? 그것의 약간 벗어난 경우에도, 나는 아직도 숫자를 얻어야한다고 생각합니다. 생각? – Carpetfizz

+0

흥미롭게도 위치 서비스를 사용하는 Twitter 앱은 내 위치를 정확하게 파악합니다. – Carpetfizz

답변

2

는 단순히 표준지도 응용 프로그램은 당신이 어디에 있는지 알고 있나요이 위양

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 
     CLLocation *location = newLocation; 
     NSLog(@"%f,%f",location.coordinate.latitude,location.coordinate.longitude); 
} 
+0

완벽하게 작동했습니다. – Carpetfizz

+1

didUpdateLocations는 iOS6에 새로운 기능이므로 iOS5 장치에서 작동하지 않습니다. –

관련 문제