Fetching the User’s Current Location

Where am I? What am I surrounded by? How do I get where I want to go? With the advent of modern technology, existential questions like these can be easily answered – and, with the Parse SDK in hand, often in a mere handful of lines of code.

PFGeoPoint can now be leveraged to return the user’s current location, without having to manage your own CLLocationManager and delegate callbacks. With the newly added +geoPointForCurrentLocationInBackground:, you can work with the current user’s location directly as a PFGeoPoint:

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

More information about our Geo functionality can be found in the iOS Guide.

Christine Yen
October 30, 2012
blog comments powered by Disqus

Comments are closed.

Archives

Categories

RSS Feed Follow us Like us