在我的应用程序中,我从 Web 服务中检索数据并在 uitableview 中显示它很好,但问题是在 mu tableview 中假设检索城市名称后有 10 行(即我表中所有城市的城市名称和纬度经度)试图获取用户位置和城市之间的距离,所以我需要调用 google mapAPI 10 次,在这个过程中我的应用程序崩溃了。我正在使用NSURLRequest
我也使用过 ASIHttpRequest - networkQueue 但没有成功。那么还有多少其他方法可以做到这一点?请建议我任何其他类型的请求来修复它。感谢您的任何建议。这是我的代码
for (NSUInteger i=0; i<[latlongarray count]; i++)
{
NSString *urlString=[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/distancematrix/json?origins=%@&destinations=%@&avoid=tolls&sensor=true",str,[latlongarray objectAtIndex:i]];
NSLog(@"%@",urlString);
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *myrequest=[[NSURLRequest alloc] initWithURL:url];
CustomConnection *distanceconnection=[[CustomConnection alloc] initWithRequest:myrequest delegate:self startImmediately:YES tag:[NSNumber numberWithInt:i]];
[distanceconnection start];
[distanceconnection release];
[myrequest release];
}
str 是用户位置,latlongarray 是城市位置的数组。