gpt4 book ai didi

ios - 何时使用 MKMapView 的 MKUserTrackingMode 与位置管理器的开始更新位置?

转载 作者:可可西里 更新时间:2023-11-01 01:28:05 29 4
gpt4 key购买 nike

我正在制作一个跟踪用户位置的应用程序,目前我正在使用以下代码执行此操作(一旦用户已授权跟踪其位置):

 override func viewDidLoad() {

super.viewDidLoad()

// set map View delegate
mapView.delegate = self

// turn on user tracking mode to follow user

if tracking == true {
mapView.userTrackingMode = MKUserTrackingMode.follow

} else {
mapView.userTrackingMode = MKUserTrackingMode.none
}


}

这似乎可以很好地跟踪用户的位置,我想知道何时使用它以及何时使用 locationManager.startUpdatingLocation()stopUpdatingLocation() .

最佳答案

当您的唯一目的是更新 map 时,您会使用 userTrackingMode。但有时我们希望用户位置用于其他目的(例如将其记录在某些数据库中,使用它来查看我们可能提供哪些商店和/或基于位置的特价商品等)。事实上,本地图可能根本不显示或至少尚未显示时,我们可能会使用 CLLocationManager

因此,如果您只关心更新 map ,那么您可以使用 userTrackingMode。但是,如果您关心独立于任何视觉 map 的位置,请使用 CLLocationManager

关于ios - 何时使用 MKMapView 的 MKUserTrackingMode 与位置管理器的开始更新位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40435307/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com