简体   繁体   中英

Getting Current Location using Parse SDK

I'm trying to get the current location of the user using the build in geoPointForCurrentLocation method. 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.

[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:

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

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

}

and I set the info.plist key for when in use authorization.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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