我试了一些东西。我猜你想获取纬度、经度和时间戳。
下面是纬度和经度的示例。
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
var locationManager: CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func showLocation(_ sender: Any) {
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
if(CLLocationManager.locationServicesEnabled()){
locationManager.startUpdatingLocation()
}
locationManager.stopUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let userLocation:CLLocation = locations[0] as CLLocation
print("user latitude = \(userLocation.coordinate.latitude)")
print("user longitude = \(userLocation.coordinate.longitude)")
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error)
{
print("Error \(error)")
}
}
let date = NSDate()
print(date)
2017-12-17 21:45:39 +0000
user latitude = 37.3322499
user longitude = -122.056264
在我的示例中,时间看起来是这样的,因为我来自欧盟,但您可以将其转换为您想要的格式。
您可以将此添加到单独的视图中,并使用
view.bringSubview(toFront: YourView)
我希望这对你有所帮助!