简体   繁体   English

使用Parse SDK获取当前位置

[英]Getting Current Location using Parse SDK

I'm trying to get the current location of the user using the build in geoPointForCurrentLocation method. 我正在尝试使用geoPointForCurrentLocation方法中的构建获取用户的当前位置。 I try to set the geoPoint in a custom field i created in my User class called location and then attempt to save it using the saveInBackground method. 我尝试在我的User类(称为location)中创建的自定义字段中设置geoPoint,然后尝试使用saveInBackground方法保存它。

[PFGeoPoint geoPointForCurrentLocationInBackground: ^(PFGeoPoint *geoPoint, NSError *error) {
    if (!error)
    {                
        [[PFUser currentUser] setObject: geoPoint forKey: @"location"];                
        [[PFUser currentUser] saveInBackground];                
    }            
}];

No errors are thrown but the user's location is not saved to the database. 没有引发任何错误,但用户的位置未保存到数据库。

Edit: 编辑:

My viewDidLoad method looks like this: 我的viewDidLoad方法看起来像这样:

self.locationManager = [[CLLocationManager alloc] init]; self.locationManager = [[[CLLocationManager alloc] init]; self.locationManager.delegate = self; self.locationManager.delegate =自我;

if ([self.locationManager
    respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
    [self.locationManager requestWhenInUseAuthorization];
} 

} }

and I set the info.plist key for when in use authorization. 并且我为使用授权设置了info.plist密钥。

没有用CLLocationManagerDelegate标记我的实现文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM