How can I get the GPS coordinates of a UIImage after the picture was taken in a UIImagePickerController? Does the image contain the coordinates in it's metadata or should I create a class for the image and its coordinates and save that? Thank you.
Asked
Active
Viewed 4,138 times
4
3 Answers
4
Please try to look at this and do as said in that answer..
I had done that and got success..
Hope It works for you..

Community
- 1
- 1

Mehul Mistri
- 15,037
- 14
- 70
- 94
2
Actually, you can access the metadata of an image right after you take the picture. The protocol method that is called by the system after an image has been selected is,
(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
The NSDictionary argument, info, contains a key: UIImagePickerControllerMediaMetadata
AFAIK, You will need CLLocationManager to get the current location and geotag it.

Damitha Raveendra
- 1,721
- 17
- 24
1
From iOS 8 onwards you can use Photos Framework.
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let url = info[UIImagePickerControllerReferenceURL] as? URL
if url != nil {
let fetchResult = PHAsset.fetchAssets(withALAssetURLs: [url!], options: nil)
let asset = fetchResult.firstObject
print(asset?.location?.coordinate.latitude)
print(asset?.creationDate)
}
}

Community
- 1
- 1

Aravindhan
- 15,608
- 10
- 56
- 71