使用Parse与iOS分离PFGeopoint的经度和经度

时间:2015-02-22 00:22:15

标签: ios parse-platform

我正在使用Parse对象填充表格视图。有一个类行是PFGeopoint。 我需要将locationitude的纬度和经度值分开,以便在表格视图单元格中显示它们。

我一直在Parse文档中搜索,在SO中搜索,但唯一的方法是:

PFGeoPoint has latitude and longitude properties. They are both doubles. Just use... theGeoPoint.latitude etc...

但在我的情况下,单元格正在获得像这样的PFObject:

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
                        object:(PFObject *)object
{
    static NSString *cellIdentifier = @"cell";

    PFTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[PFTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                      reuseIdentifier:cellIdentifier];
    }

    // Configure the cell to show todo item with a priority at the bottom
    cell.textLabel.text = object[@"restaurant_name"];
    cell.detailTextLabel.text = object [@"cadena"];

    PFImageView *thumbnailImageView = (PFImageView*)[cell viewWithTag:100];

    thumbnailImageView=[[PFImageView alloc] initWithFrame:CGRectMake(9, 9, 30, 30)];
    [thumbnailImageView setBackgroundColor:[UIColor clearColor]];


    PFFile *thumbnail = object[@"image"];
    cell.imageView.image = [UIImage imageNamed:@"placeholder.jpg"];
    cell.imageView.file = thumbnail;


    return cell;
}

我如何将纬度和经度与对象分开,就像我要获取名称行一样:object[@"restaurant_name"]

谢谢。

1 个答案:

答案 0 :(得分:0)

最后我找到了解决方案。在我的cellForRowAtIndex方法中,我需要创建一个PFGeopoint,然后获取纬度和经度的值,如下所示:

PFGeoPoint *myRestaurant = object[@"restaurant_coordinates"];
NSString *string = [NSString stringWithFormat:@"%@, %@",
                        [numberFormatter stringFromNumber:[NSNumber numberWithDouble:myRestaurant.latitude]],
                        [numberFormatter stringFromNumber:[NSNumber numberWithDouble:myRestaurant.longitude]]];
cell.detailTextLabel.text = string;