我想找到现在的位置,但我没有得到现在的位置

时间:2017-06-14 13:50:58

标签: ios iphone

我正在尝试查找当前位置坐标,但我的程序没有调用didUpdateLocations方法。我还在NSLocationWhenInUseUsageDescription中添加了info.plist。请帮忙(我使用的是7.2(7C68)版)。我只测试模拟器。

import UIKit
import CoreLocation
import MapKit


class ViewController: UIViewController, CLLocationManagerDelegate {
var location: CLLocationManager!

override func viewDidLoad() {
    let location = CLLocationManager()
    location.delegate = self
    location.desiredAccuracy = kCLLocationAccuracyBest
    location.startUpdatingLocation()
    location.requestWhenInUseAuthorization()



    super.viewDidLoad()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()

}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
    let cord = locations[0] as CLLocation
   let lati =  cord.coordinate.latitude
    let long = cord.coordinate.longitude
    print(lati,"",long)

}


}

0 个答案:

没有答案