作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在制作一个跟踪用户位置的应用程序,目前我正在使用以下代码执行此操作(一旦用户已授权跟踪其位置):
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/
我正在尝试实现一个自定义按钮来跟踪 MKUserTrackingMode。我知道有一个 MKUserTrackingBarButtonItem 但是我不能使用它,因为我的按钮不在工具栏/导航栏中,所以
我正在制作一个跟踪用户位置的应用程序,目前我正在使用以下代码执行此操作(一旦用户已授权跟踪其位置): override func viewDidLoad() { super.viewDidL
我是一名优秀的程序员,十分优秀!