iphone - How do I get the current location from the location manager? -
i want app exact location (longitude , latitude) of every second, possible ? have code far, every 3 second app current location doesnt update if move...
- (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation{ nslog(@"lol"); [locationmanager stopupdatinglocation]; if (wtf == 2) { [[nsuserdefaults standarduserdefaults] setobject:newlocation forkey:@"old"]; nslog(@"wtf"); wtf =0; } oldlocation = [[nsuserdefaults standarduserdefaults] objectforkey:@"old"]; double rep = [oldlocation distancefromlocation:newlocation]; nsstring *label1 = [nsstring stringwithformat:@"%2.90f",oldlocation.coordinate.latitude]; nsstring *label2 = [nsstring stringwithformat:@"%2.90f",newlocation.coordinate.latitude]; if ([label1 isequal:label2]) { nslog(@"penis"); } labelm.text = label1; labelkm.text = label2; } - (void)locationmanager:(cllocationmanager *)manager didfailwitherror:(nserror *)error { } -(void)actualise{ [locationmanager startupdatinglocation]; } - (void)viewdidload { [super viewdidload]; wtf = 2; locationmanager = [[cllocationmanager alloc] init]; locationmanager.delegate = self; locationmanager.desiredaccuracy = kcllocationaccuracybest; [locationmanager startupdatinglocation]; [nstimer scheduledtimerwithtimeinterval:3 target:self selector:@selector(actualise) userinfo:nil repeats:yes]; } /*
use code initialize , start location manager:
locationmanager = [[cllocationmanager alloc] init]; locationmanager.delegate = self; locationmanager.distancefilter = kcldistancefilternone; locationmanager.desiredaccuracy = kcllocationaccuracynearesttenmeters; [locationmanager startupdatinglocation];
and implement didupdatetolocation this:
- (void) locationmanager:(cllocationmanager*)manager didupdatetolocation:(cllocation*)newlocation fromlocation:(cllocation*) oldlocation { // called every time device has new location information. }
there no need use timers.
Comments
Post a Comment