簡體   English   中英

通過解析獲取用戶位置

[英]Getting the Users location with parse

我正在嘗試使我的代碼在應用程序加載時使用用戶當前時間和位置更新我的解析數據庫。 這是我當前的代碼:


- (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模擬器時無法正常工作。 謝謝。

解析博客中提供了示例代碼:

[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];
    }
}];

根據我的意見。 您必須從完成塊中保存位置。 您是從模塊外部完成的。

您也可以看看iOS 地理位置指南

希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM