0

I need to access the GPS coordinates of user-submitted photos that originate from the user's camera roll/photo library. I'm implementing PHAsset instead of ALAsset for the sake of modernity.

I know that location services ARE enabled because I can print out the user's current location and have added the "NSLocationAlwaysUsageDescription", "NSLocationWhenInUseDescription", and "privacy - location usage description" keys to my info.plist file. I've imported CoreLocation, MobileCoreServices, and Photos in the .h file for my ViewController.

My current code in the didFinishPickingMediaWithInfo delegate method is as follows:

NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL];
PHFetchResult *res = [PHAsset fetchAssetsWithALAssetURLs:[NSArray arrayWithObject:url] options:nil];
PHAsset *thisPhoto = [res objectAtIndex: 0];
CLLocation *photoLocation = [thisPhoto location];
NSLog(@"%@", photoLocation);

For some reason, this always outputs (null). Is there something I'm missing that's stopping me from accessing PHAsset location data? I know that the PHAsset is being properly assigned because [PHAsset creationDate] works fine for any photo that I choose.

Thanks!

kmb
  • 3
  • 2

1 Answers1

2

You do have access to PHAsset location data (provided it is available). The user could have chosen to not allow the camera app to access location services which results in photos without location data.

Joe Smith
  • 1,900
  • 1
  • 16
  • 15
  • Looks like you're right. Why do certain photos have location data while others don't? At least in my own photo library, it seems like photos nearly alternate between having location data and not having it, even though I've never disallowed location services on my phone. Any idea why? – kmb May 22 '15 at 17:02
  • The other cases I know of are: screenshots captured on phone (no location data), some photos synced from iTunes (may or may not have location data). In your case, you need to rule out reception issues for GPS. Either try it outdoors or make sure WIFI is on. – Joe Smith May 22 '15 at 20:56