2012-06-18 46 views
0

当我调用Google API获取地址时,我在这里调用API。Google Api与Json一起使用

-(void)searchviews:(NSString*)EditString selector:(SEL)sel 
{ 
    NSLog(@"Welcome To Search views"); 

    searchviews=sel; 
    NSString *path =[NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?address=%@&sensor=false",EditString]; 

    NSURL *url=[NSURL URLWithString:path]; 
    NSLog(@"hiii---%@",url); 
    ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:url]; 
    [request setRequestMethod:@"POST"]; 
    [request setDelegate:self]; 
    [request startAsynchronous]; 
    [drkSignUp showWithMessage:nil]; 
    NSLog(@" Complet--------------- "); 

和对于请求方法我打电话一样。

- (void)requestFinished:(ASIHTTPRequest *)request { 

    //NSLog(@"%@",[request responseString]); 

    NSString *func = [self getFunc:[request url]]; 

    NSLog(@"%@\n%@",func,[request responseString]); 

if ([func isEqual:@"json?address=%@&sensor=false"]) 
      { 
       NSDictionary *resDict = [parser objectWithString:[request responseString] error:nil]; 
       NSLog(@"---- ResData%@",resDict); 
       NSString *result = [resDict objectForKey:@"successful"]; 
       NSLog(@"hiiiii google api calling............"); 

       [drkSignUp hide]; 
       [self.delegate performSelector:searchviews withObject:[resDict objectForKey:@"results"]]; 

就是这样,但问题在乐趣中创造。当我打电话

if ([func isEqual:@"json?address=%@&sensor=false"]) 

它不调用cos它是动态String.So我应该在func中置入%@的位置?

回答

0

您可以填写的ASIFormDataRequest的用户信息字典像下面

//After this line 
ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:url]; 
//Add 
request.userInfo = [NSDictionary dictionaryWithObject:@"EditString" forKey:@"request"]; 

然后在

- (void)requestFinished:(ASIHTTPRequest *)request { 
    //Get the request userInfo 
    NSString *str = [request.userInfo objectForKey:@"request"]; 
    //now fill the request string 
    NSString *requestString = [NSString stringWithFormat:@"json?address=%@&sensor=false", str]; 
    //Check it with func 
    if ([func isEqual:requestString]) 
    { 
     //Continue your procedure 
    } 
} 
+0

@dipangsheth欢迎您。如果它有用,也不要忘记upvote和/或接受答案:) –

相关问题