Get location of selected photo Swift

Reading time ~1 minute

The purpose of this block of code is to print to the console the city and region where the photo, selected via standard ios image picker controller, was taken.

In this example I used ALAssets from AssetsLibrary.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//UIImagePickerControllerDelegate Methods
func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info: NSDictionary!){
    let library = ALAssetsLibrary()
    let URL: AnyObject? = info["UIImagePickerControllerReferenceURL"]
    var error: NSError?
    library.assetForURL(URL as NSURL, resultBlock: { (asset) -> Void in
        let location = asset.valueForProperty(ALAssetPropertyLocation) as? CLLocation
        let geocoder = CLGeocoder()
        geocoder.reverseGeocodeLocation(location!) { (data, error) -> Void in
            let address = data[0].addressDictionary!
            let city = address[kABPersonAddressCityKey] as  NSString!
            let state = address[kABPersonAddressStateKey] as  NSString!
            println(city, state)
        }
    }) { (error) -> Void in
        println(error)
    }
}

How to Download Multiple Instagram Photos at Once?

You want to print your Insta photos or just keep them save and archived? Out of luck - there is no obvious way to download them, unless y...… Continue reading

Polymer and Vulcanization

Published on August 08, 2016

Jeff Dean of Google

Published on August 06, 2016