GeoCoding and setting global variables iOS -


i pretty new ios development please bare me =]

i have 2 global nsstring variables called mylocality , mycountry...

i have set geocode below:

    - (void) locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation {     finishedgettinglocation = false;     if (newlocation.horizontalaccuracy < 200.0f){         [locationmanager stopupdatinglocation];         clgeocoder * geocoder = [[clgeocoder alloc] init];         __block nsstring *locality;         __block nsstring *country;         [geocoder reversegeocodelocation:newlocation completionhandler:^(nsarray *placemarks, nserror *error) {             (clplacemark * placemark in placemarks) {                 locality = placemark.locality;                 country = placemark.isocountrycode;             }         }];         {          } while ([geocoder isgeocoding]);          mylocality = locality;         mycountry = country;          finishedgettinglocation = true;             }     } 

and background thread follows:

- (void) dowork {     dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_background, 0), ^{                             finishedgettinglocation = false;          dispatch_async(dispatch_get_main_queue(), ^{             locationmanager = [[cllocationmanager alloc] init];             [locationmanager setdelegate:self];              [locationmanager setdesiredaccuracy:kcllocationaccuracyhundredmeters];             [locationmanager startupdatinglocation];         });          int counter = 0;         {             [nsthread sleepfortimeinterval:.1];             counter ++;             if (counter % 200 == 0){                 dispatch_async(dispatch_get_main_queue(), ^{                     toast *otoast = [toast toastwithmessage:@"gps pin-pointing works faster if outside"];                     [otoast showonview:self.view];                 });                 counter = 0;             }          } while (!finishedgettinglocation);        nslog(@"%@", mycountry); // trying print       nslog(@"%@", mylocality); // trying print      }); } 

(yeah, know it's pretty sloppy code, but, meh.. xd)

now, can't figure out why these returning null when log them in code elsewhere. however, when put log in above for, i.e nslog(@"%@", placemark.locality) correct value, or @ least value.

how can set global variables placemark?

where these variables declared?

if make mylocality , mycountry static in class doing geocoding, other classes can access them once set.

another way create @protocol , have class wants results of geocoding receive callback once it's done.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -