【问题标题】:Getting the Users location with parse通过解析获取用户位置
【发布时间】:2015-06-26 04:15:06
【问题描述】:

我正在尝试让我的代码在应用加载时使用用户当前时间和位置更新我的解析数据库。这是我当前的代码:


- (void)viewDidLoad {
    [super viewDidLoad];
   PFObject *testObject = [PFObject objectWithClassName:@"TestObject"];
   testObject[@"foo"] = @"bar";
//    PFGeoPoint *point = [PFGeoPoint geoPointWithLatitude:40.0 longitude:-30.0];
//    testObject[@"location"] = point;
    [PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error) {
        if (!error) {
            testObject[@"location"] = geoPoint;
        }
    }];

    [testObject saveInBackground];

当我给它一个预设的经纬度和经度以供使用时,我的数据库会正确更新,但是当我使用解析代码来获取用户 geoPoint 时它不起作用。这是因为我做错了还是因为当我在我的电脑上使用 iPhone 模拟器时它不起作用。谢谢。

【问题讨论】:

  • 你在获取位置之前保存了testObject,把它写在完成块中

标签: ios xcode parse-platform geolocation cllocationmanager


【解决方案1】:

解析blog中给出了示例代码:

[PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error) {
    if (!error) {
        NSLog(@"User is currently at %f, %f", geoPoint.latitude, geoPoint.longitude);

        [[PFUser currentUser] setObject:geoPoint forKey:@"currentLocation"];
        [[PFUser currentUser] saveInBackground];
    }
}];

根据我的意见。您必须从完成块中保存位置。你已经从街区的外面完成了。

你也可以看看Geo Location的iOS指南

希望对你有帮助。

【讨论】:

  • 我试图从完成块中保存位置,但数据永远无法解析。
猜你喜欢
  • 1970-01-01
  • 2016-08-21
  • 2016-11-08
  • 1970-01-01
  • 2013-01-16
  • 2012-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多