iPhone 中可以使用多少种类型的 URLRequest 从 Web 服务检索数据?

发布于 2024-11-29 11:16:22 字数 1028 浏览 5 评论 0原文

在我的应用程序中,我从网络服务检索数据并在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乱了心跳 2024-12-06 11:16:22

您可以使用同步或异步方式进行 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文