我正在进行Twitter搜索,需要获取每条推文的确切位置以在地图上绘制。我已经设置了核心位置,我的“获取推文”的代码如下所示。
我目前正在循环获取文本组件,但我不确定如何获取推文附带的位置组件。您将在下面看到几行我已经添加到循环中以尝试提取位置,但是它将显示为空/空。
•我是否将NSString * twitlocation定位在循环中的正确位置?将这个收集的位置与每个推文的正确文本结合起来我是从单独的数组调用它,即来自推文1的文本和推文1的位置将在我运行objectAtIndex:0时结婚吗? •为什么twitterLocation的日志为null? •我是否正确将位置放在NSString中以添加到数组中,或者它应该是不同的对象?
FYI是
谢谢!
- (void)fetchTweets
{
AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
//NSLog(@"phrase carried over is %@", delegate.a);
// Do a simple search, using the Twitter API
TWRequest *request = [[TWRequest alloc] initWithURL:[NSURL URLWithString:
[NSString stringWithFormat:@"http://search.twitter.com/search.json?q=%@", delegate.a]]
parameters:nil requestMethod:TWRequestMethodGET];
// Notice this is a block, it is the handler to process the response
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if ([urlResponse statusCode] == 200)
{
// The response from Twitter is in JSON format
// Move the response into a dictionary and print
NSError *error;
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&error];
//NSLog(@"Twitter response: %@", dict);
NSArray *results = [dict objectForKey:@"results"];
//Loop through the results
for (NSDictionary *tweet in results) {
// Get the tweet
NSString *twittext = [tweet objectForKey:@"text"];
//looping through to also get the location of each tweet
NSString *twitlocation = [tweet objectForKey:@"location"];
// Save the tweet to the twitterText array
[_twitterText addObject:twittext];
//adding the twitlocation to the location array
[twitterLocation addObject:twitlocation];
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
NSLog(@"MY ************************LOCATION************** %@", twitterLocation);
}
else
NSLog(@"Twitter error, HTTP response: %i", [urlResponse statusCode]);
}];
}