0
这是我的场景。在应用程序开始在iOS中获取位置
在应用程序开始第一次我需要用户的位置,以获取最接近他们的位置列表。
如果他们允许位置访问,然后我想要使用他们的位置向他们展示位置列表。
我打电话更新了didUpdateLocation中的列表,但即使在允许第一次访问后,列表也是空的。当我第二次打开应用程序时,该位置可用,并且我有坐标并可以继续显示可用的列表。
我也曾尝试运行代码来填充论文列表2种委托方法:
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus){
// switch statements then
fectchPlacesAndPopulateList()
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
print("locationManager")
Utils.creatErrorMessage(title: "aaa", message: "aaaa", vc: self)
let userLocation:CLLocation = locations[0] as! CLLocation
let lng = userLocation.coordinate.longitude;
let lat = userLocation.coordinate.latitude;
let coordinates = "\(lat),\(lng)"
print("update locations = \(coordinates)")
fectchPlacesAndPopulateList()
}
var locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.startUpdatingLocation()
}
}
是否调用了'didUpdateLocations'? – NobodyNada
@NobodyNada,不,它不叫 – raklos
我认为它被称为在某一点,但不是在我点击允许后。我需要在我有位置 – raklos