Skip to content

Instantly share code, notes, and snippets.

@Busta117
Created June 13, 2015 21:22
Show Gist options
  • Save Busta117/f7e7e81d9c2098505359 to your computer and use it in GitHub Desktop.
Save Busta117/f7e7e81d9c2098505359 to your computer and use it in GitHub Desktop.
address from cords
class func getAddressFromCoords(coords:CLLocationCoordinate2D, complete:(location:Location?, error:NSError?)->()){
var url = "http://maps.googleapis.com/maps/api/geocode/json"
var str = String(format: "%f",coords.latitude) + "," + String(format:"%f",coords.longitude)
var params = ["latlng":str, "sensor":true]
AFHTTPRequestOperationManager().GET(url, parameters: params, success: { (operation:AFHTTPRequestOperation!, response:AnyObject!) -> Void in
let json:JSON = JSON(response)
var loc = Location(dictionary: json)
loc.locationCoord = coords
complete(location:loc , error: nil)
}) { (operation:AFHTTPRequestOperation!, error:NSError!) -> Void in
println(error)
complete(location: nil, error: error)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment