Parse.Com Pfgeopoint.Geopointforcurrentlocationinbackground Not Doing Anything

Parse.com PFGeoPoint.geoPointForCurrentLocationInBackground not doing anything

I had the same problem. It's fixed in Parse 1.4.0.

Also you need to add the following key/value pair to your app's info.plist:

<key>NSLocationWhenInUseUsageDescription</key>
<string>We want to send your location data to the NSA, please allow access to location services. (replace this text with whatever you want the dialog to say)</string>

References:

  • Parse SDK for iOS 8
  • CLLocationManager in iOS 8 - use of NSLocationWhenInUseUsageDescription

Parse and Swift Geopoints not saving

That is because you are setting it but you are not saving the value you just set:

if signUpError == nil {
PFGeoPoint.geoPointForCurrentLocationInBackground {
(geoPoint: PFGeoPoint?, error: NSError?) -> Void in
if error == nil {
PFUser.currentUser()!.setValue(geoPoint, forKey: "location")
PFUser.currentUser().saveInBackground()
}
}

withinMiles not working with Parse PFGeopoint query in Swift

to get user location it can take couple seconds, that is why PFGeoPoint.geoPointForCurrentLocationInBackground is not running on the main thread, put your query inside that and it will work... Also i think that the query by distance is limited only to 100 Miles

PFGeoPoint.geoPointForCurrentLocationInBackground {
(geoPoint: PFGeoPoint?, error: NSError?) -> Void in
if error == nil {
let query = PFUser.query()
query!.whereKey("addressPoint", nearGeoPoint: geoPoint, withinMiles: 100)
//... rest of the query
}
}

Does a parse.com geoPointForCurrentLocationInBackground count as an API request

Tim virtually anything that you do with Parse counts against your API request limit. Look at them for what they are as a business, they collect revenue off of API request/s. So obviously the more you do the better for them. If you take a look at their definition of what constitutes an API request you will see a very vague, yet explicit answer. see here specifically the first question for reference.

Anytime you make a network call to Parse on behalf of your app using one of the Parse SDKs or REST API, it counts as an API request.

So take a look at your code, your calling something in the background, so yes if you were fetching it from Parse you would however in this circumstance it is using the devices location as you mentioned in your question.
CLLocationManager delegate delivers new coordinates and all geoPointForCurrentLocationInBackground does is encapsulates that.
Additionally, to answer your comment, queries do fall under this as well.

As a safe bet assume all your tasks are using an API request, this will create better coding habits and smarter structure outlines.

I believe the only thing that isn't used against you is cached information, which makes sense, since your originally already retrieved the information with an initial query there is no need to use another API request to get the same data as cached.

Sidenote: this even applies to the new local data store, even though it's not technically online, it will update the backend that you made a local data store query/save.


REFERENCE : https://parse.com/docs/ios/api/Classes/PFGeoPoint.html#//api/name/geoPointForCurrentLocationInBackground:

Can't retrieve geopoint with geoPointForCurrentLocationInBackground

There's a solution posted on Parse.com PFGeoPoint.geoPointForCurrentLocationInBackground not doing anything. Basically update Parse to the latest version and add the NSLocationWhenInUseUsageDescription key to your Info.plist, this is a change made in iOS 8 and is needed whenever you want to use an users location within your app.

iOS 8 Parse.com update and pf geopoint current location

[PFGeoPoint geopointForCurrentLocationInBackground] will only be called if you have first called your CLLocationManager engaged and have asked the user for permission to show their location.

You also need to update the (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status method for iOS 8.

Something like this is what I use:

// Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7.
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
else {
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];

//<<PUT YOUR CODE HERE AFTER LOCATION IS UPDATING>>
}

You also need to implement the locationmanager delegate method to handle changes is location authorization status, like so:

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
switch (status) {
case kCLAuthorizationStatusDenied:
NSLog(@"kCLAuthorizationStatusDenied");
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Location Services Not Enabled" message:@"The app can’t access your current location.\n\nTo enable, please turn on location access in the Settings app under Location Services." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertView show];
}
break;
case kCLAuthorizationStatusAuthorizedWhenInUse:
{
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];

CLLocation *currentLocation = locationManager.location;
if (currentLocation) {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setCurrentLocation:currentLocation];
}
}
break;
case kCLAuthorizationStatusAuthorizedAlways:
{
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];

CLLocation *currentLocation = locationManager.location;
if (currentLocation) {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setCurrentLocation:currentLocation];
}
}
break;
case kCLAuthorizationStatusNotDetermined:
NSLog(@"kCLAuthorizationStatusNotDetermined");
break;
case kCLAuthorizationStatusRestricted:
NSLog(@"kCLAuthorizationStatusRestricted");
break;
}
}

parse geoPointForCurrentLocationInBackground Swift sample

You are right about missing a few things before you can handle the location update from Parse.

First, add a location manager property to your class.

class TableViewController: UITableViewController, CLLocationManagerDelegate {

var locationManager = CLLocationManager()

Set its delegate and use it to request authorization from the user:

override func viewDidLoad() {
super.viewDidLoad()

locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()

print("Get GPS")
PFGeoPoint.geoPointForCurrentLocationInBackground { (geoPoint, error ) -> Void in
if error == nil {
print("Got geoPoint") //Never reaches this
print(geoPoint)
} else {
print(error ) //No error either
}
}
}

In your Info.plist, you need to add a key NSLocationWhenInUseUsageDescription and give it a string value for a message to the user during the authorization request.

The authorization request and the location update should work after the above changes.

I can't understand why my query is not working

The error arises because you're passing a nil value to whereKey:nearGeoPoint: as self.userLocation is unlikely to be set the first time the view loads. You will want to do two things:

  1. In your queryForTable method, check if self.userLocation is nil. If it is, return nil. This acts as a no-op and the table won't show any data just yet.

    - (PFQuery *)queryForTable
    {
    if (!self.userLocation) {
    return nil;
    }
    // User's location
    PFGeoPoint *userGeoPoint = self.userLocation;
    // Create a query for places
    PFQuery *query = [PFQuery queryWithClassName:@"MainInfo"];
    // Interested in locations near user.
    [query whereKey:@"geoPoint" nearGeoPoint:userGeoPoint];
    // Limit what could be a lot of points.
    query.limit = 10;
    // Final list of objects
    _placesObjects = [query findObjects];

    return query;
    }
  2. In your geoPointForCurrentLocationInBackground: completion block, once the self.userLocation value is set, you will want to call [self loadObjects]. This will tell the PFQueryTableViewController to run your query again, and this time around self.userLocation will not be nil, allowing you to construct your original query. Fortunately, you've already performed this step, but I've included it here in case anyone else has the same question.

No returns for Parse query

I believe the issue is that Parse treats the User class as a special class. You may have difficulty querying User class if you treat it as if it was a Custom Class.

The correct and tested way to do this is to the the query function of PFUser.

var query = PFUser.query()


Related Topics



Leave a reply



Submit