我似乎无法在标签上显示经纬度。我尝试了很多东西,但我猜它可能很简单。
import Foundation
import UIKit
import CoreLocation
import MapKit
class LocationVC: UIViewController, CLLocationManagerDelegate {
var location: CLLocation! {
didSet{
longLabel.text = ("\(location.coordinate.latitude)")
latLabel.text = ("\(location.coordinate.longitude)")
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
let location = locations[0]
let span:MKCoordinateSpan = MKCoordinateSpanMake(0.5, 0.5)
let myLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
let region:MKCoordinateRegion = MKCoordinateRegionMake(myLocation, span)
map.setRegion(region, animated: true)
print("hhhhh\(location.coordinate.latitude)")
print(location.altitude)
print(location.speed)
self.map.showsUserLocation = true
}
所有 View 均已正确设置。
最佳答案
您没有更改类的 location
变量的值,这将触发标签的文本更改。将此附加到 didUpdateLocations
:
self.location = location
关于ios - 以编程方式将纬度和经度放在 UILabel 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46525470/