I'm trying to do simple thing. I want to find an array of addresses and show it on map. But then I need to pass data to another view.
The problem is: I need to pass data from dictionary which contains address, so, I need to know which exactly address was found. Request is async and main-thread only so I can't understand what address was found right now.
Sorry if I'm talking not clear.
for (NSDictionary *dic in adresses) {
MKLocalSearch *search = [[MKLocalSearch alloc]initWithRequest:request];
request.naturalLanguageQuery = [dic valueForKey:@"adress"];
[search startWithCompletionHandler:^(MKLocalSearchResponse
*response, NSError *error) {
if (response.mapItems.count == 0){
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc]init];
[dictionary setValue:request.naturalLanguageQuery forKey:@"realadress"];
[dictionary setValue:@"empty" forKey:@"itemname"];
[adressesonmap addObject:dictionary];
[array addObject:@"empty"];
//HERE I NEED TO KNOW WHICH ADRESS MAPKIT TRIED TO FIND!!!
}
else{
for (MKMapItem *item in response.mapItems)
{
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc]init];
[dictionary setValue:request.naturalLanguageQuery forKey:@"realadress"];
[dictionary setValue:item.name forKey:@"itemname"];
[adressesonmap addObject:dictionary];
[matchingItems addObject:item];
MKPointAnnotation *annotation = [[MKPointAnnotation alloc]init];
annotation.coordinate = item.placemark.coordinate;
annotation.title = request.naturalLanguageQuery;
//HERE I NEED TO KNOW WHICH ADRESS MAPKIT TRIED TO FIND!!!
// here I'me trying to get address, which I tried to find before in request, but it's always one of them (from request.naturalLanguageQuery)
[_mapView addAnnotation:annotation];
}
}
}];
}