所以我一直在致力于一项获取用户位置的任务。
我编写了这段代码,它可以在模拟器上很好地构建和运行。
但它无法获取我当前的位置。
我是不是漏掉了什么?如果是这样,请帮忙!
这是我的代码:
最佳答案
您可以尝试将 didUpdateLocation 更改为此。
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let userLocation:CLLocation = locations[0] as CLLocation
locationManager.stopUpdatingLocation()
let location = CLLocationCoordinate2D(latitude: userLocation.coordinate.latitude, longitude: userLocation.coordinate.longitude)
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegion(center: location, span: span)
myMap.setRegion(region, animated: true)
}
希望对您有帮助。
关于ios - 获取用户位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39707949/