iPhone 中可以使用多少种类型的 URLRequest 从 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 是城市位置的数组。
In my app i am retrieve data from web services and show in uitableview it is fine but problem is that in mu tableview suppose 10 row (that is city name and latitude longitude of all city that are in my table) after the retrieve city name i m trying to get Distance between user location and city so 10 times i need to call google mapAPI, in that process my app is crash.
i am using NSURLRequest
i had also used ASIHttpRequest - networkQueue but not get success.
so how many other ways to do this?
please suggest me any other types of request to fix it.
thanx for any suggestion.
here is my code
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 is user location, and latlongarray is array for city's location.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用同步或异步方式进行 NSURLRequest 操作。据我所知,当进一步执行依赖于响应时,异步处理 NSURLRequest 更为可取。
You can go NSURLRequest operation with either synchronous or asynchronous way. According to me, dealing with NSURLRequest asynchronously is more advisable when response being is depended for further executions.