import
UIKit
import
CoreLocation
class
ViewController
:
UIViewController
,
CLLocationManagerDelegate
{
let
locationManager:
CLLocationManager
=
CLLocationManager
()
@IBOutlet
weak
var
label1:
UILabel
!
@IBOutlet
weak
var
label2:
UILabel
!
@IBOutlet
weak
var
label3:
UILabel
!
@IBOutlet
weak
var
label4:
UILabel
!
@IBOutlet
weak
var
label5:
UILabel
!
@IBOutlet
weak
var
label6:
UILabel
!
@IBOutlet
weak
var
label7:
UILabel
!
override
func
viewDidLoad() {
super
.viewDidLoad()
locationManager.delegate =
self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.distanceFilter = 100
locationManager.requestAlwaysAuthorization()
if
(
CLLocationManager
.locationServicesEnabled())
{
locationManager.startUpdatingLocation()
print
(
"定位开始"
)
}
}
func
locationManager(manager:
CLLocationManager
, didUpdateLocations locations: [
CLLocation
]) {
let
currLocation:
CLLocation
= locations.last!
label1.text =
"经度:\(currLocation.coordinate.longitude)"
label2.text =
"纬度:\(currLocation.coordinate.latitude)"
label3.text =
"海拔:\(currLocation.altitude)"
label4.text =
"水平精度:\(currLocation.horizontalAccuracy)"
label5.text =
"垂直精度:\(currLocation.verticalAccuracy)"
label6.text =
"方向:\(currLocation.course)"
label7.text =
"速度:\(currLocation.speed)"
}
}
请发表评论