使用Swift 3查找用户坐标

时间:2017-04-01 04:48:00

标签: swift xcode swift3 geolocation core-location

我正在开发一个需要使用用户位置的项目。我试过这样做,但很多在线教程都不适合我。

我添加了info.plist"隐私 - 使用时的位置使用说明"并添加了构建短语" CoreLocation"。

我也尝试过代码 -

import UIKit
import MapKit
import CoreLocation

class CloseBeaches: UIViewController, CLLocationManagerDelegate {


let manager = CLLocationManager()

var locationManager: CLLocationManager!

override func viewDidLoad() {
    print("Working")
    super.viewDidLoad()
    self.locationManager = CLLocationManager()
    locationManager.requestWhenInUseAuthorization()
    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.startMonitoringSignificantLocationChanges()
}
func locationManager(_ manager: CLLocationManager,didUpdateLocations locations: [CLLocation]) {
    let locValue:CLLocationCoordinate2D = manager.location!.coordinate
    print("locations = \(locValue.latitude) \(locValue.longitude)")
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}


}

但是最终没有印刷品。

有没有办法可以轻松找到用户坐标并打印出来。

先谢谢

0 个答案:

没有答案