iphone - Cant get new location after stopUpdatingLocation - IOS -
i'm trying users gps coordinates app, works fine, once. when view gets called run code , location - - when view want new coordinates old ones chashed in phone.
here code:
#import "postpictureviewcontroller.h" @interface postpictureviewcontroller () @end @implementation postpictureviewcontroller { cllocationmanager *locationmanager; } - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization } return self; } - (void)viewdidload { [super viewdidload]; } -(void) viewdidappear:(bool)animated{ locationmanager = [[cllocationmanager alloc] init]; [self getlocation]; } -(void)getlocation{ locationmanager.delegate = self; locationmanager.desiredaccuracy = kcllocationaccuracybest; [locationmanager startupdatinglocation]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } #pragma mark - cllocationmanagerdelegate - (void)locationmanager:(cllocationmanager *)manager didfailwitherror:(nserror *)error { nslog(@"didfailwitherror: %@", error); uialertview *erroralert = [[uialertview alloc] initwithtitle:@"fel" message:@"error" delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil]; [erroralert show]; } - (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation { nslog(@"didupdatetolocation: %@", newlocation); cllocation *currentlocation = newlocation; if (currentlocation != nil) { nslog([nsstring stringwithformat:@"%.8f", currentlocation.coordinate.longitude]); nslog([nsstring stringwithformat:@"%.8f", currentlocation.coordinate.latitude]); } // stop location manager [locationmanager stopupdatinglocation]; //this screwing locationmanager = nil; }
.h
#import <uikit/uikit.h> #import <corelocation/corelocation.h> @interface postpictureviewcontroller : uiviewcontroller<cllocationmanagerdelegate> @end
i think problem [locationmanager stopupdatinglocation];
line stop locationmanager after getting coordinates first time. have tried without line , works - updates coordinates - dont want locationmanager
send me new coordinates every second. need them once per view-time.
anyone got clue? in advance
try in way:
- (void)viewdidload { [super viewdidload]; locationmanager = [[cllocationmanager alloc] init]; [self getlocation]; } -(void) viewwillappear:(bool)animated{ [locationmanager startupdatinglocation]; } -(void)getlocation{ locationmanager.delegate = self; locationmanager.desiredaccuracy = kcllocationaccuracybest; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } #pragma mark - cllocationmanagerdelegate - (void)locationmanager:(cllocationmanager *)manager didfailwitherror:(nserror *)error { nslog(@"didfailwitherror: %@", error); uialertview *erroralert = [[uialertview alloc] initwithtitle:@"fel" message:@"error" delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil]; [erroralert show]; } - (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation { nslog(@"didupdatetolocation: %@", newlocation); cllocation *currentlocation = newlocation; if (currentlocation != nil) { nslog([nsstring stringwithformat:@"%.8f", currentlocation.coordinate.longitude]); nslog([nsstring stringwithformat:@"%.8f", currentlocation.coordinate.latitude]); } // stop location manager [locationmanager stopupdatinglocation]; //this screwing } - (void)viewdidunload { locationmanager = nil; }
Comments
Post a Comment