0

So I am using parse to get an update of the users location and data from that query like so:

-(void) getUserLocationAndData:(BOOL) showProgress
{
    [PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error)
     {
         if (!error)
         {
             NSLog(@"Got current location - Zooming Map!");
             CLLocationCoordinate2D zoomLocation;
             zoomLocation.latitude  = geoPoint.latitude;
             zoomLocation.longitude = geoPoint.longitude;

             [self getNearByData:geoPoint];
         }
         else
         {
             [[[UIAlertView alloc] initWithTitle:@"Unable to get Current Location" message:@"This app needs your current location in order to locate near by data. Please check your internet connection and make sure you enabled access to the location information." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil] show];
         }
     }];
}

When the app first launches the user location shows up, the data is pulled and everything works. If you wait about 15 seconds and don't move the user location icon turns gray (see image) and any updates result in a failure. If I reload the view it works again but the same thing happens.

I am not using a CLLocationManager because I do not need to constantly pull the data near the user. Just every so often or on demand by the user.

I have also noticed if I wait long enough the user location goes Blue again and all seems to work. What is causing this timeout? Can I set this timeout, or do I need to just use a CLLocationManager to have any control of this? Is Parse just timing out with an internal CLLocationManager or something?

Thanks for the help!

enter image description here

enter image description here

David Nelson
  • 752
  • 1
  • 10
  • 27

1 Answers1

0

So evidently when you use the Parse function: geoPointForCurrentLocationInBackground Parse will take over with it's own internal CLLocationManager. After it does it's initial thing it stops updating the location (or possibly only updates the user location if the user moves enough.. again just a guess here.. and if that feature is supported on the device).

The solution is to create your own CLLocationManager in your view controller and instead of calling

geoPointForCurrentLocationInBackground 

You simply store the updated user location and call:

PFGeoPoint *usersGeoPoint = [PFGeoPoint geoPointWithLocation:usersLastKnownLocation];

And now we can use that to query near by data. We are now responsible for starting and stopping the updating of the user location. I strongly recommend using this post to setup your own LocationManager and be sure to scroll down to the updated answers for more up to date info. How can I get current location from user in iOS

After reading about the geoPointWithLocation in the Parse docs I made the conclusions above. Please read it for yourself (I know it's really hard to find and just one line...)

Community
  • 1
  • 1
David Nelson
  • 752
  • 1
  • 10
  • 27