Reading the Gps Data from the Image Returned by the Camera in iOS Iphone

Reading the GPS data from the image returned by the camera in iOS iphone

One possibility is to leaving CoreLocation running when the camera is visible. Record each CCLocation into an array along with the time of the sample. When the photo comes back, find its time, then match the closest CClocation from the array.

Sounds kludgy but it will work.

Extract GPS data from photo

I found a solution using the following code:

 if picker.sourceType == UIImagePickerControllerSourceType.PhotoLibrary
{
if let currentLat = pickedLat as CLLocationDegrees?
{
self.latitude = pickedLat!
self.longitude = pickedLong!
}
else
{
var library = ALAssetsLibrary()
library.enumerateGroupsWithTypes(ALAssetsGroupAll, usingBlock: { (group, stop) -> Void in
if (group != nil) {

println("Group is not nil")
println(group.valueForProperty(ALAssetsGroupPropertyName))
group.enumerateAssetsUsingBlock { (asset, index, stop) in
if asset != nil
{
if let location: CLLocation = asset.valueForProperty(ALAssetPropertyLocation) as CLLocation!
{ let lat = location.coordinate.latitude
let long = location.coordinate.longitude

self.latitude = lat
self.longitude = lat

println(lat)
println(long)
}
}
}
} else
{
println("The group is empty!")
}
})
{ (error) -> Void in
println("problem loading albums: \(error)")
}
}
}

What it does is that it reads the entire album and prints the location if the photo has that property, else it prints "location not found". It does so for every photo in the album.So I have another question... I want to display the location info just for the photo that I have selected, not for the entire album. Does anyone have a clue how this can be accomplished?

UIImagePickerController from camera: Get back image with location data

To finish this up:

I use a CLLocationManager to get my current location and then inject it to my nsdata that I sent using the code that can be found here:

https://stackoverflow.com/a/5294574/516627

Bests,
Philip

UIImagePickerControllerReferenceURL returns nil, crashing the app

So it sounds like there are actually two questions here:

1) Why is UIImagePickerControllerReferenceURL returning a nil reference?

2) How can you get location data from the photo?

So, the answer to (1) is usually because you receive the callback didFinishPickingMedia before the OS as written the file to the image library.

The answer to #2 is much trickier, as showcased by this question's line of answers:
Reading the GPS data from the image returned by the camera in iOS iphone

There are a number of variables you need to account for:

  • iOS will strip the GPS data out if you haven't requested access to location data, so you'll need to prompt for location access using CLLocationManager.
  • If the user has geotagging disabled, you'll never get GPS coords.
  • If the phone can't get a GPS lock, iOS won't record the GPS coords.

Per this answer: https://stackoverflow.com/a/10338012/490180 you should be able to retrieve the raw UIImage and then create the CGImageSourceRef from the data property off of UIImage's CGImage. This effectively removes the need for you to ever access the ReferenceURL.



Related Topics



Leave a reply



Submit