Swift basics-Positioning

Source: Internet
Author: User

Swift basics-Positioning

//// ViewController. swift // JieCoreLocation /// Created by jiezhang on 14-10-4. // Copyright (c) jiezhang. all rights reserved. // import UIKitimport CoreLocationclass ViewController: UIViewController, CLLocationManagerDelegate {required init (coder aDecoder: NSCoder) {super. init (coder: aDecoder)} @ IBOutlet weak var longitudeTxt: UITextField! @ IBOutlet weak var latitudeTxt: UITextField! @ IBOutlet weak var HeightTxt: UITextField! @ IBOutlet weak var addressTxt: UILabel! Var currLocation: CLLocation! // Address decompilation error. I am simulating @ IBAction func reverseGeocode (sender: AnyObject) {var geocoder = CLGeocoder () var p: CLPlacemark on the simulator? 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]? CLPlacemark println (p)} else {println ("No Placemarks! ")} // Used to locate the service management class. It can provide us with location information and height information, or monitor the device's entry or exit from a certain area, you can also obtain the operation direction of the device. let locationManager: CLLocationManager = CLLocationManager () override func viewDidLoad () {super. viewDidLoad () locationManager. delegate = self // The highest precision locationManager when the device is powered by a battery. desiredAccuracy = kCLLocationAccuracyBest // precise to 1000 m, distance filter, defines the minimum distance from the device to obtain location information after moving locationManager. distanceFilter = kCLLocationAccuracyKilometer} override fu Nc viewWillAppear (animated: Bool) {locationManager. startUpdatingLocation () println ("")} override func viewWillDisappear (animated: Bool) {locationManager. stopUpdatingLocation () println ("")} func locationManager (manager: CLLocationManager !, DidUpdateLocations locations: [AnyObject]!) {CurrLocation = locations. last as CLLocation longitudeTxt. text = "\ (currLocation. coordinate. longpolling) "latitudeTxt. text = "\ (currLocation. coordinate. latitude) "HeightTxt. text = "\ (currLocation. altitude) "} func locationManager (manager: CLLocationManager !, DidFailWithError error: NSError !) {Println (error)} override func didReceiveMemoryWarning () {super. didReceiveMemoryWarning ()}}





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.