iphone - locationManager:didUpdateLocations: always be called several times -
i start updating current location when view did appear, , stop updating location whenever locationmanager:didupdatelocations:
called. why locationmanager:didupdatelocations:
called several times? have missed?
#import "viewcontroller.h" @interface viewcontroller (){ cllocationmanager *locationmanager; // location manager current location } @end @implementation viewcontroller - (void)viewdidload { [super viewdidload]; } - (void)viewdidappear:(bool)animated { [super viewdidappear:animated]; [self startupdatingcurrentlocation]; } - (void)startupdatingcurrentlocation { if (!locationmanager) { locationmanager = [[cllocationmanager alloc] init]; [locationmanager setdelegate:self]; locationmanager.distancefilter = 10.0f; // don't need more accurate 10m } [locationmanager startupdatinglocation]; } -(void)locationmanager:(cllocationmanager *)manager didupdatelocations:(nsarray *)locations{ [locationmanager stopupdatinglocation]; } @end
probably depends accuracy set locationmanager. have 3 kinds o localization cell radio, wifi map, gps. if set best accuracy location manager continue check position, if location better accuracy out of range of distance filter delegate method called again.
Comments
Post a Comment