Swift Basics-Positioning

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.