使用解析获取用户位置
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 模拟器时它不起作用。谢谢
示例代码在解析中给出 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];
}
}];
根据我的意见。您必须从完成块中保存位置。你已经从街区外面完成了。
您还可以查看 iOS Geo Location
指南
希望对您有所帮助。
我正在尝试让我的代码在加载应用程序时使用用户当前时间和位置更新我的解析数据库。这是我当前的代码:
- (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 模拟器时它不起作用。谢谢
示例代码在解析中给出 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];
}
}];
根据我的意见。您必须从完成块中保存位置。你已经从街区外面完成了。
您还可以查看 iOS Geo Location
指南希望对您有所帮助。