• Swift基础--定位


    //
    //  ViewController.swift
    //  JieCoreLocation
    //
    //  Created by jiezhang on 14-10-4.
    //  Copyright (c) 2014年 jiezhang. All rights reserved.
    //
    
    import UIKit
    import CoreLocation
    
    class 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!
        
        //地址反编译出错误,不清楚什么问题,我是在模拟器上模拟的
        @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!") } }) } //用于定位服务管理类。它能够给我们提供位置信息和高度信息。也能够监控设备进入或离开某个区域,还能够获得设备的执行方向 let locationManager : CLLocationManager = CLLocationManager() override func viewDidLoad() { super.viewDidLoad() locationManager.delegate = self //设备使用电池供电时最高的精度 locationManager.desiredAccuracy = kCLLocationAccuracyBest //精确到1000米,距离过滤器。定义了设备移动后获得位置信息的最小距离 locationManager.distanceFilter = kCLLocationAccuracyKilometer } override func 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.longitude)" latitudeTxt.text = "(currLocation.coordinate.latitude)" HeightTxt.text = "(currLocation.altitude)" } func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!){ println(error) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } }





  • 相关阅读:
    Java-IO之DeflaterOutputStream和InflaterOutputStream
    myeclipse 破解步骤
    通过Nginx,Tomcat访问日志(access log)记录请求耗时
    关于封装了gevent的request grequest库的使用与讨论
    关于python性能相关测试cProfile库
    python threading模块使用 以及python多线程操作的实践(使用Queue队列模块)
    python格式化字符串Type Error: Format Requires Mapping 的问题
    关于flask自带web应用服务器Werkzeug 使用requests请求时出现的错误。
    关于python 自带csv库的使用心得 附带操作实例以及excel下乱码的解决
    pycharm5.0 快捷键大全osx
  • 原文地址:https://www.cnblogs.com/yfceshi/p/6943465.html
Copyright © 2020-2023  润新知