2016-06-22 4 views
0

私のアプリにGoogleオートコンプリートAPIを追加しましたが、わかりません。私はまた、 "INVALID REQUEST"を取得しています。私もdeveloper.google.comをチェックしますが、解決策が見つかりません。私はAFNetwrokを使用しています。GoogleオートコンプリートAPIが「INVALID REQUEST」になる

はここ

NSString *strURL = [NSString stringWithFormat:@"%@key=%@",AutoComplete_URL,GOOGLE_KEY]; 
    NSDictionary *params = @{@"input" : [@"Paris" stringByReplacingOccurrencesOfString:@" " withString:@"+"],@"sensor":@"true"}; 
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; 
    [manager POST:strURL parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { 
     if (responseObject) { 
      [APPDELEGATE hideLoadingView]; 
      if ([[responseObject valueForKey:@"status"] isEqualToString:@"OK"]) { 
       arrAutocomplete = [[responseObject valueForKey:@"predictions"] valueForKey:@"description"]; 
       NSLog(@"AUTO: %@", arrAutocomplete); 
      } 
      else{ 
       // [APPDELEGATE showpToastWithTitle:[response valueForKey:@"msg"]]; 
       //[self.tableView setHidden:YES]; 
      } 
     } 
     else{ 
      [APPDELEGATE hideLoadingView]; 
      [APPDELEGATE showToastWithTitle:@"Please check your internet connection"]; 
     } 
     NSLog(@"JSON: %@", responseObject); 
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
     NSLog(@"Error: %@", error); 
     [APPDELEGATE hideLoadingView]; 
     [APPDELEGATE showToastWithTitle:@"Something going wrong"]; 
    }]; 

OUTPUT私のコードです: -

JSON:

{ 
    predictions =  (
    ); 
    status = "INVALID_REQUEST"; 
} 

答えて

0

は、私はそれを得ました。

NSString *string = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/autocomplete/json?key=%@&types=geocode&input=%@",GOOGLE_KEY,address]; 
    NSURL *url = [NSURL URLWithString:string]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:url]; 

    // 2 
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; 
    operation.responseSerializer = [AFJSONResponseSerializer serializer]; 

    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 

     if (responseObject) { 
      NSLog(@"%@",responseObject); 
     } 
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 

     // 4 
     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Weather" 
                  message:[error localizedDescription] 
                  delegate:nil 
                cancelButtonTitle:@"Ok" 
                otherButtonTitles:nil]; 
     [alertView show]; 
    }]; 

    // 5 
    [operation start]; 
関連する問題