gpt4 book ai didi

swift - 如何在labels-swift上显示经纬度

转载 作者:行者123 更新时间:2023-11-28 05:33:13 25 4
gpt4 key购买 nike

我试图在名为经度和纬度的 2 个标签上显示经度和纬度,但我没有得到任何结果。

import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate{

@IBOutlet weak var longitude: UILabel!
@IBOutlet weak var latitude: UILabel!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
if (CLLocationManager.locationServicesEnabled()) {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
} else {
println("Location services are not enabled");
}
}
// MARK: - CoreLocation Delegate Methods
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
locationManager.stopUpdatingLocation()
removeLoadingView()
if ((error) != nil) {
print(error)
}
}

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
var locationArray = locations as NSArray
var locationObj = locationArray.lastObject as CLLocation
var coord = locationObj.coordinate
longitude.text = coord.longitude
latitude.text = coord.latitude

}
}

我在 longitude.text =coord.logitude 上有错误,第二个表也一样,它说它无法转换为字符串。我是 Swift 的新手。

最佳答案

您将数字转换为字符串,例如:

longitude.text = "\(coord.longitude)"

关于swift - 如何在labels-swift上显示经纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26715243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com