2011-08-12 24 views
0

在我的應用程序中,我從Web服務中檢索數據,並在uitableview中顯示它是好的,但問題是,在mu tableview中,假設在檢索城市後10行(即城市名稱和所有城市的緯度經度)名稱即時嘗試獲取用戶位置和城市之間的距離,所以10次我需要調用谷歌地圖API,在那個過程中我的應用程序崩潰。 我正在使用NSURLRequest 我也曾使用ASIHttpRequest - networkQueue但沒有得到成功。 那麼有多少其他方法可以做到這一點? 請建議我解決它的任何其他類型的請求。對於任何建議,都可以使用thanx( )。 這裏是我的代碼iPhone中有多少種類型的URLRequest可用於從WebServices中檢索數據?

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是陣列城市的位置。

+0

請顯示一些代碼。請求數量沒有限制。 – Moshe

+0

確保你沒有結束釋放一些對象,這通常會導致崩潰。 –

+0

你可以發佈整個google mapAPI參數嗎? –

回答

0

您可以使用同步或異步方式進行NSURLRequest操作。根據我的觀點,當響應被依賴於進一步執行時,異步處理NSURLRequest更爲明智。

+1

那麼這不是真的...... – Robin

+0

@robin:是否有任何其他類型使用NSURLRequest?請告訴我。 –

+0

您能否簡單解釋一下它是否正確? –

相關問題