【问题标题】:getting text and coordinates from a tweet in objective c从目标 c 中的推文中获取文本和坐标
【发布时间】:2013-01-02 02:13:30
【问题描述】:

我正在遍历一系列返回的推文以获取文本组件和坐标。我已经将代码设置如下,这会检索文本而不是坐标。我不确定我做错了什么。我检查了返回的路径,返回的字符串的一部分包含 eg

"geo":{"coordinates":[51.479361,-0.215066],"type":"Point"},

所以肯定会返回一个坐标。这是我的代码...

for (NSDictionary *tweet in results) {
                 // Get the tweet
                 NSString *twittext = [tweet objectForKey:@"text"];

                 // Save the tweet to the twitterText array
                 [_twitterText addObject:twittext];


id jsonResult = [tweet valueForKeyPath:@"geo.coordinates"];
                 if ([NSNull null] != jsonResult) {
                     if (2 == [jsonResult count]) {
                         NSDecimalNumber* longitude = [jsonResult objectAtIndex:0];
                         NSDecimalNumber* latitude = [jsonResult objectAtIndex:1];
                         if (longitude && latitude) {

                             // here you have your coordinates do whatever you like
                             [twitterLocation addObject:[NSString stringWithFormat:@"%@,%@", latitude, longitude]];
                         }
                         else {
                             NSLog(@"Warning: bad coordinates: %@", jsonResult);
                         }
                     }
                     else {
                         NSLog(@"Warning: bad coordinates: %@", jsonResult);
                     }
                 }*/
             }

【问题讨论】:

    标签: objective-c xcode coordinates geo


    【解决方案1】:

    首先check,如果获得的值为NSStringNSDecimalNumber

    if([jsonResult objectAtIndex:0] && [jsonResult objectAtIndex:1])  
    {
       if([[jsonResult objectAtIndex:0] isKindOfClass:[NSString class]])
        {  
           double longitude = [[jsonResult objectAtIndex:0] doubleValue];
           double latitude = [[jsonResult objectAtIndex:1] doubleValue];
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-18
      • 2011-04-26
      • 2022-10-13
      • 1970-01-01
      • 2010-10-02
      • 1970-01-01
      • 2011-09-19
      相关资源
      最近更新 更多