在我的代码中,我需要初始化我的用户位置:它工作正常。
但每当我想更改我的位置(通过选择地址或在屏幕上滑动)时,我的应用程序都会将我带回我的用户位置。
我在 that post 上找到了一些答案.
但是,我不调用 didUpdateUserLocation()
。所以我不知道该怎么办。
我的应用是否经常调用 ViewDidLoad()
?
这是我的代码,我在其中初始化我的位置。
var usrLocation: CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
if (CLLocationManager.locationServicesEnabled()) {
usrLocation = CLLocationManager()
usrLocation.delegate = self
usrLocation.requestAlwaysAuthorization()
usrLocation.requestLocation()
usrLocation.startUpdatingLocation()
}
mapView.delegate = self
}
此外,我不能只删除我的 usrLocation.requestLocation()
函数,我需要在应用启动时以我的用户为中心。我想在其他地方调用它,但我不知道在哪里?
最佳答案
你已经实现了
usrLocation.startUpdatingLocation()
这是不断更新位置,所以只要您指向另一个位置,它就会更新用户位置。
删除此行代码将起作用。
关于ios - 自动调用用户位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38747727/