iphone - Geocode + MKPointAnnotation not playing nicely -


i'm having weirdest issue, , it's doing head in. global variable i've set within singleton reporting correctly within function it's set in, null within next function (which need access it), correct view! variable correctly set, it's not behaving within function. there weird error warning being generated offending line (which i've marked between *).

the warning is:

property access result unused - getters should not used side effects. 

apologies spotty code. i'm prototyping , learning go, it's mishmash of things i've cobbled net. code recognise long tap on mapview, , places pin @ location (while recording location), , i'm trying use geocode show address @ pin position.

the first function follows:

- (void)handlelongpress:(uigesturerecognizer *)gesturerecognizer { if (gesturerecognizer.state != uigesturerecognizerstatebegan)     return;  cgpoint touchpoint = [gesturerecognizer locationinview:self.fullmapview]; cllocationcoordinate2d touchmapcoordinate = [self.fullmapview convertpoint:touchpoint tocoordinatefromview:self.fullmapview];  //save new birthplace in global variable         globalssingle.gblbirthplace = touchmapcoordinate;  //place user location , record mkuserlocation *location = fullmapview.userlocation; globalssingle.gblcurrentlocation = location.coordinate;  //first remove previous birthplace pin [self removeallpinsbutuserlocation];  [self reversegeocode];  //place new birthplace pin mkpointannotation *birthplacepin = [[mkpointannotation alloc] init]; birthplacepin.coordinate = touchmapcoordinate; birthplacepin.title = @"my birthplace"; **** birthplacepin.subtitle = @"%@", globalssingle.gbladdress; **** [self.fullmapview addannotation:birthplacepin];  nslog(@"gbladdress = %@", globalssingle.gbladdress);  } 

the above function calls next:

-(void)reversegeocode {  clgeocoder *ceo = [[clgeocoder alloc]init]; cllocation *loc = [[cllocation alloc]initwithlatitude:globalssingle.gblbirthplace.latitude     longitude:globalssingle.gblbirthplace.longitude]; //insert coordinates  [ceo reversegeocodelocation: loc completionhandler:  ^(nsarray *placemarks, nserror *error) {      clplacemark *placemark = [placemarks objectatindex:0];      //string hold address      nsstring *locatedat = [[placemark.addressdictionary  valueforkey:@"formattedaddresslines"] componentsjoinedbystring:@", "];       // save address text      globalssingle.gbladdress = locatedat;      nslog(@"addressdictionary %@", placemark.addressdictionary);     nslog(@"placemark %@",placemark.region);     nslog(@"placemark %@",placemark.country);  // give country name     nslog(@"placemark %@",placemark.locality); // extract city name     nslog(@"location %@",placemark.name);     nslog(@"location %@",placemark.ocean);     nslog(@"location %@",placemark.postalcode);     nslog(@"location %@",placemark.sublocality);     nslog(@"location %@",placemark.location);    //print location console      nslog(@"i @ %@",locatedat);      nslog(@"gbladdress reverse geocode = %@", globalssingle.gbladdress);      }  ]; } 

what's weirder (to me) nslog's within reversegeocode printing correctly, nslog first function reporting null, , printing before 1 reversegeocode though it's (i assume) being executed second! example, debug output is:

2013-05-21 23:41:04.662 project name[5659:c07] gbladdress = (null) 2013-05-21 23:41:04.808 project name[5659:c07] gbladdress reverse geocode = januária - mg, brazil 

any bothered offer i'd appreciate, i'm bamboozled :)

the method reversegeocodelocation:completionhandler: executed asynchronously, means move on next lines before finishes.

asynchronous vs synchronous execution, mean?

it called asynchronously because method reversegeocodelocation:completionhandler: might need time it, , when finished, completion block called.

you should place new birthplace pin after completion block of reversegeocodelocation called, example inside completion block, ensure have got placemark data first before placing pin. or can update subtitle of newly added pin inside completion block.

[ceo reversegeocodelocation: loc completionhandler:  ^(nsarray *placemarks, nserror *error) {      clplacemark *placemark = [placemarks objectatindex:0];      //string hold address      nsstring *locatedat = [[placemark.addressdictionary  valueforkey:@"formattedaddresslines"] componentsjoinedbystring:@", "];       // save address text      globalssingle.gbladdress = locatedat;       //place new birthplace pin      mkpointannotation *birthplacepin = [[mkpointannotation alloc] init];      birthplacepin.coordinate = globalssingle.gblbirthplace;      birthplacepin.title = @"my birthplace";      birthplacepin.subtitle = globalssingle.gbladdress;      [self.fullmapview addannotation:birthplacepin];     }  ]; } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -