【发布时间】:2017-02-13 18:18:07
【问题描述】:
我是初学者,我学习 Swift 只是为了好玩。现在我正在研究应用程序中地图的使用,我想将当前坐标(纬度,经度)打印到标签上。
现在,我已经设法在地图上显示地图和当前位置并获取它的坐标,但我需要帮助我如何将这些坐标打印到标签上。
这是我到目前为止所做的:
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var posizione: UILabel!
//Map
@IBOutlet weak var map: MKMapView!
@IBAction func rileva(_ sender: Any)
{
}
let manager = CLLocationManager()
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
let location = locations[0]
let span:MKCoordinateSpan = MKCoordinateSpanMake(0.01, 0.01)
let myLocation: CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
let region:MKCoordinateRegion = MKCoordinateRegionMake(myLocation, span)
map.setRegion(region, animated: true)
print(location.coordinate)
print(location.altitude)
self.map.showsUserLocation = true
}
【问题讨论】: