viewcontroller.swift//jiecorelocation////Created by Jiezhang on 14-10-4.//Copyright (c) 2014 Jiezhang. All rights Reserved.//import Uikitimport Corelocationclass Viewcontroller:uiviewcontroller, cllocationmanagerdelegate{Required Init (coder Adecoder:nscoder) {super.init (Coder:adecoder)} @IBO Utlet weak var longitudetxt:uitextfield! @IBOutlet weak var latitudetxt:uitextfield! @IBOutlet weak var heighttxt:uitextfield! @IBOutlet weak var addresstxt:uilabel! var currlocation:cllocation! Address decompile error, unclear what problem I was impersonating on simulator @IBAction func Reversegeocode (sender:anyobject) {var geocoder = Clgeocoder () var p:clplacemark? Geocoder.reversegeocodelocation (Currlocation, Completionhandler: {(placemarks, error), Void in if error! = Nil {println ("reverse Geodcode fail: \ (error.localizeddescription)") return} Let PM = Placemarks as [Clplacemark] if (Pm.count > 0) {p = placemarks[0] as? Clplacemark println (P)}else{println ("No placemarks!") }})}//used to locate the service management class, it can provide us with location information and high information, but also can monitor the device to enter or leave an area, also can get the direction of operation of the device let Locationmanager:cllocationmanager = Cllocationmanager () override Func Viewdidload () {super.viewdidload () Locationmanager.delegate = s Elf//device highest accuracy when using battery power locationmanager.desiredaccuracy = kcllocationaccuracybest//Accurate to 1000 m, distance filter, defined device Minimum distance to get location information after moving Locationmanager.distancefilter = kcllocationaccuracykilometer} override func View Willappear (Animated:bool) {locationmanager.startupdatinglocation () println ("Positioning Start")} Override Fu NC viewwilldisappear (Animated:bool) {locationmanager.stopupdatinglocation () println ("End of Position")} Fu NC locationmanager (manager:cllocationmanager!, didupdatelocations locations: [anyobject]!) { Currlocation = Locations.last as cllocation longitudetxt.text = "\ (currLocation.coordinate.longitude)" Latitudetxt.text = "\ (currLocation.coordinate.latitude)" Heighttxt.text = "\ (currlocation.altitude)"} Fu NC locationmanager (manager:cllocationmanager!, Didfailwitherror error:nserror!) {println (Error)} override func didreceivememorywarning () {super.didreceivememorywarning () }}
Swift Basics-Positioning