2013-01-24 3 views
0

필자는 CoreLocation을 iOS 튜토리얼과 함께 시작하여 내 앱에 CoreLocation을 구현하는 방법에 대해 머리를 터뜨리기 시작했습니다. (http://www.techotopia.com/index.php/An_Example_iOS_5_iPhone_Location_Application)corelocation은 루핑을 계속합니다.

하지만이 튜토리얼을 내 응용 프로그램에 통합하려고 할 때 발생하는 문제는 지금 반복적으로 계속 반복되므로 단지 나를 괴롭 히고 있습니다. 아무도 도와 줄 수 있습니까?

GPSViewController.h

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

@interface GPSViewController : UIViewController 
@property (strong, nonatomic) CLLocationManager *locationManager; 
@property (strong, nonatomic) CLLocation *startLocation; 
@end 

GPSViewController.m

#import "GPSViewController.h" 

#import "DataClass.h" 

@interface GPSViewController() 

@end 

@implementation GPSViewController 
@synthesize locationManager, startLocation; 

DataClass *obj; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 

    //initialization og global varable. 
    DataClass *obj=[DataClass getInstance]; 

    //GPS Initialise 
    self.locationManager = [[CLLocationManager alloc] init]; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    locationManager.delegate = self; 
    [locationManager startUpdatingLocation]; 
    startLocation = nil; 

} 

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

#pragma mark - 
#pragma mark CLLocationManagerDelegate 

-(void)locationManager:(CLLocationManager *)manager 
    didUpdateToLocation:(CLLocation *)newLocation 
      fromLocation:(CLLocation *)oldLocation 
{ 
    NSString *currentLatitude = [[NSString alloc] 
           initWithFormat:@"%g", 
           newLocation.coordinate.latitude]; 
    //latitude.text = currentLatitude; 
    obj.Latatude = currentLatitude; 

    NSString *currentLongitude = [[NSString alloc] 
            initWithFormat:@"%g", 
            newLocation.coordinate.longitude]; 
    //longitude.text = currentLongitude; 
    obj.Longitude = currentLongitude; 

    NSLog(@"latitude %+.6f, longitude %+.6f\n", 
      newLocation.coordinate.latitude, 
      newLocation.coordinate.longitude); 

    if(obj.Latatude != NULL && obj.Longitude != NULL){ 
     [self performSegueWithIdentifier:@"GPSSuccess" sender:self]; 
    } 
} 

-(void)locationManager:(CLLocationManager *)manager 
     didFailWithError:(NSError *)error 
{ 
} 

- (void)viewDidUnload { 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
    self.startLocation = nil; 
    self.locationManager = nil; 
} 


@end 
+0

루핑을 통해 doUpdateToLocation을 계속 호출하는 것을 의미합니까? –

답변

3

당신은 반복해서 사용자의 위치를 ​​얻는을 중지하기 위해 [locationManager stopUpdatingLocation];를 호출해야합니다.

+0

아 그래, 나는 이것을 시도했지만 멈추기 전에 GPS 위치를 얻는 것을 멈추고 있었다. 그러나 나는 단순히 [locationManager stopUpdatingLocation]을 추가했다; 위의 줄에 [self performSegueWithIdentifier : @ "GPSSuccess"보낸 사람 : 자기]; 그리고 그것은 여전히 ​​반복적 인 문제없이 내가 원하는 세부 사항을 얻을 수있었습니다. 고맙습니다. – Beanonymous

관련 문제