ios - Pass Variable to CLLocationManager in Objective-C -


how can pass instance of avg to:

-(void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation; 

function below? want take average of array , submit external database when location updates.

- (ibaction)buttonpressed:(id)sender {      // make manager delegate & set accuracy     manager.delegate = self;     manager.desiredaccuracy = kcllocationaccuracybest;      // call timer     mytimer = [nstimer scheduledtimerwithtimeinterval:1.0                                                target:self                                              selector:@selector(arraybuild)                                              userinfo:nil                                               repeats:yes];     // initialise array     resultsarray = [[nsmutablearray alloc]init]; }  - (void)arraybuild {      loopcount++;      if (loopcount >= 11) {          // find average         nsnumber *avg = [resultsarray valueforkeypath:@"@avg.self"];          // change text of label average & log         self.signal.text = [nsstring stringwithformat:@"%@",avg];         nslog(@"%@",avg);         // want send value here ^^ didupdatelocation function          // update location         [manager startupdatinglocation];          // invalidate timer         [mytimer invalidate];         mytimer = nil;      }else{          // declare signal strength         float signalstrength = ctgetsignalstrength();          // individual result & convert integer         nsstring *result = [nsstring stringwithformat:@"%f", signalstrength];         nsinteger resultint = [result integervalue];          // add object         [resultsarray addobject:[nsnumber numberwithfloat:resultint]];          // change text of label each second         self.signal.text = [nsstring stringwithformat:@"%d",loopcount];         nslog(@"%f",signalstrength);     } }  #pragma mark cllocationmanagerdelegate methods  - (void)locationmanager:(cllocationmanager *)manager didfailwitherror:(nserror *)error {      nslog(@"error: %@", error);     nslog(@"failed location!");  }  -(void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation {      nslog(@"location: %@",newlocation);     cllocation *curentlocation = newlocation;      if (curentlocation != nil) {          float signalstrength = ctgetsignalstrength();          // code below uses third party utility submit data         pfobject *object = [pfobject objectwithclassname:@"issue"];         object[@"latitude"] = [nsstring stringwithformat:@"%.8f",curentlocation.coordinate.latitude];         object[@"longitude"] = [nsstring stringwithformat:@"%.8f",curentlocation.coordinate.longitude];         object[@"signal"] = [nsstring stringwithformat:@"%f",signalstrength];         [object saveinbackground];          // update text fields         self.latitude.text = [nsstring stringwithformat:@"%.8f",curentlocation.coordinate.latitude];         self.longitude.text = [nsstring stringwithformat:@"%.8f",curentlocation.coordinate.longitude];         self.signal.text = [nsstring stringwithformat:@"%.8f",signalstrength];     }     // stop location update     [manager stopupdatinglocation]; } 

i thought involved [self manager:avg] or similar? i'm not sure what.

use instance variable (or property) average variable, way can calculate , set in arraybuild function , have accessible in didupdatelocation function.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -