ios - How to get place name from lattitude and longitude? -


i getting latitude , longitude api, , need place name these cooridinates use block of code

clgeocoder *ceo = [[clgeocoder alloc]init];  cllocation *locationatual=[[cllocation alloc] initwithlatitude:[[latlong objectforkey:@"latitude"] doublevalue]                                                       longitude:[[latlong objectforkey:@"longitude"] doublevalue]];  nslog(@"loc %@", locationatual);  [ceo reversegeocodelocation:locationatual  completionhandler:^(nsarray *placemarks, nserror *error) {   clplacemark *placemark = [placemarks objectatindex:0];   nslog(@"placemark %@",placemark);   //string hold address   nsstring *locatedat = [[placemark.addressdictionary valueforkey:@"formattedaddresslines"] componentsjoinedbystring:@", "];   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);    nslog(@"i @ %@",locatedat);   nslog(@"  "); } ]; 

but when control goes on line

 [ceo reversegeocodelocation:locationatual  completionhandler:^(nsarray *placemarks, nserror *error)   

this block of code not executed. control goes.

in viewdidload ofyour class or other class add:

- (void)viewdidload {     [super viewdidload]; // add observer         [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(gotplaceinfo:) name:@"gotplaceinfonotification" object:nil]; }  //define `gotplaceinfo`: -(void)gotplaceinfo:(nsnotification *)notif{  nslog(@"place mark dict  %@", notif.userinfo); } 

i have add single line in code:

    clgeocoder *ceo = [[clgeocoder alloc]init];      cllocation *locationatual=[[cllocation alloc] initwithlatitude:[[latlong objectforkey:@"latitude"] doublevalue]                                                           longitude:[[latlong objectforkey:@"longitude"] doublevalue]];      nslog(@"loc %@", locationatual);      [ceo reversegeocodelocation:locationatual  completionhandler:^(nsarray *placemarks, nserror *error)     {       clplacemark *placemark = [placemarks objectatindex:0];  nsdictionary *currentlocationdictionary = @{@"clplacemark":clplacemark};       nslog(@"placemark %@",placemark);       //string hold address       nsstring *locatedat = [[placemark.addressdictionary valueforkey:@"formattedaddresslines"] componentsjoinedbystring:@", "];       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);        nslog(@"i @ %@",locatedat);       nslog(@"  "); nsnotification *notification2 = [nsnotification notificationwithname:@"gotplaceinfonotification" object:self userinfo:currentlocationdictionary];     [[nsnotificationcenter defaultcenter] postnotification:notification2];     }     ]; 

hope give overall learning


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -