[Swift] Pulling GPS data from a photo and making a location comparison

Discussion in 'iOS Programming' started by Poxer, May 4, 2015.

  1. Poxer macrumors newbie

    Joined:
    Apr 17, 2014
    #1
    I'm still learning Swift and I'm currently attempting a CloudKit based database tutorial. I have it figured out for the most part. The CloudKit data includes a String Attribute, a Location attribute, and an image Asset.

    I'm currently focusing on the image asset. In tinkering with the code, I have it so I can view the image asset, remove it from the viewcontroller, load in a new photo (from the camera roll) to replace the image with something else and re-upload it to CloudKit (which overwrites the existing image). That all works great.

    I'd like to try something a little more challenging but I'm unable to locate any source material to help.

    What I want to do is take the image asset's GPS data (lat/lon), which was taken with an iPhone with Location Services enabled, and compare it to the CloudKit Location data for that record where the image asset was held, and make sure they're very close to each other.

    I don't really need CoreLocation, since I'm not caring about the iPhone's location. But I don't know how to query the image data's lat/lon GPS coordinates and make comparisons to the record's Location attribute.

    Looking over the Apple documentation, I think the answer might be related to CGImageProperties, and more specifically kCGImagePropertyGPSLongitude and kCGImagePropertyGPSLatitude. Unfortunately, my GoogleFu is only turning up older references to ObjC code, which I don't understand. So I'm trying to find some sort of examples in Swift so I can get myself moving forward.

    If anyone could give me a push in the right direction, that would be great.
     
  2. xArtx macrumors 6502a

    Joined:
    Mar 30, 2012
    #2
    Hi I could probably help if you were writing Obj-C, but without understanding of Swift,
    what variables can you see?
    If you get an example Obj-C code that writes the Lat/Lon to C float or double is that any good to you?
     
  3. 1458279 Suspended

    1458279

    Joined:
    May 1, 2010
    Location:
    California
    #3
    Someone here had an example of using both ObjC and Swift in the same app. One option is to use an ObjC routine in your Swift app.

    Another option is to read the ObjC code and see how it works, then dupe that in Swift.
     
  4. Poxer thread starter macrumors newbie

    Joined:
    Apr 17, 2014
    #4
    If you can help in Obj-C, then I'll try to convert it into Swift.

    Any type of help you can provide would be helpful. As for the variables I can see, I don't know. The code I'm working on calls the UIImagePickerController and allows the user to pick an image from their phone. After they choose, I want to read the metadata of the image they've chosen, and specifically pull the latitude and longitude from the image.

    Then I've got a CloudKit record with a 'Location' field that's holding individual latitude and longitude coordinates for each record.

    What I'm ultimately going to do with the metadata info is compare the photo with the stored CloudKit location info and make sure the photo was taken near the coordinates of the location. If it is, it'll let the photo be uploaded. If not, it'll toss up an error saying the photo wasn't taken near the location.

    I can hopefully figure out everything else, but without knowing how to pull the metadata gps info from the photo after the ImagePicker, I can't really move on to the rest. At this point, even code in Obj-C would probably help. The Cocoa Touch stuff is pretty universal it seems. Once I see that, I can probably change it into Swift syntax.
     

Share This Page