first i made a NSString with the address i need
NSString *bldgAddress = [NSString stringWithFormat:@"%@ %@ %@", listingsDisplayed.ADDRESS1, listingsDisplayed.TOWN, listingsDisplayed.ZIPCODE];
then i called LMGeocoder Github Link
[[LMGeocoder sharedInstance] geocodeAddressString:bldgAddress service:kLMGeocoderGoogleService completionHandler:^(LMAddress *address , NSError *error) {
if (address && !error) {
_latitude = [NSString stringWithFormat:@"%f", address.coordinate.latitude];
_longitude = [NSString stringWithFormat:@"%f", address.coordinate.longitude];
} else {
NSLog(@"%@", error);
}}];
it works fine up to here, _lat and _long are declared in my .h file and the values are assigned respectively
cell.lat.text = [NSString stringWithFormat:@"%@,%@", _latitude, _longitude];
issue start when i try to load that data into the cell, it shows (null),(null). i dont understand why the values disappear, any help would be greatly appreciated
Edit: Code that worked thanks to @dhanush
__block UILabel *currentLAbel = cell.lat;
[[LMGeocoder sharedInstance] geocodeAddressString:bldgAddress service:kLMGeocoderGoogleService completionHandler:^(LMAddress *address , NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (address && !error) {
listingsDisplayed.Latitude = [NSString stringWithFormat:@"%f", address.coordinate.latitude];
listingsDisplayed.Longitude = [NSString stringWithFormat:@"%f", address.coordinate.longitude];
currentLAbel.text = [NSString stringWithFormat:@"%@,%@", listingsDisplayed.Latitude, listingsDisplayed.Longitude];
cell.lat = currentLAbel;
} else {
NSLog(@"%@", error);
}
});
}];
Try This
You should always do UI Changes in Main thread. Initially Those values are null. Once you got those values you can set it inside the block. CurrentLabel will help to get the particular label if you are scrolling the table. try with cell.lat. if it is not working use the current label.