import UIKit
import CoreLocation
class ViewController: UIViewController {
lazy var locationM: CLLocationManager = {//info.plist add :Privacy - Location Always Usage Description
let locationM = CLLocationManager()
locationM.delegate = self
if #available(iOS 8.0, *) {
locationM.requestAlwaysAuthorization()
}
return locationM
}()
lazy var geoCoder: CLGeocoder = {
return CLGeocoder()
}()
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
locationM.startUpdatingLocation()
}
}
extension ViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let newLocation = locations.last else {return}
print(newLocation)//<+31.26514482,+121.61259089> +/- 50.00m (speed 0.00 mps / course -1.00) &#
swift地图定位(八)获取当前城市名称(定位+反地理编码)
最新推荐文章于 2024-04-25 12:56:40 发布