如何解决注释不显示
进入地图视图控制器后,UITabBarItem必须在将注释添加到地图之后执行操作
MapViewController类:UIViewController,UITabBarDelegate {
@IBOutlet weak var middleMapButton: UITabBarItem!
@IBOutlet weak var mapView: MKMapView!
let locationManager = CLLocationManager()
let regionInMeters: Double = 10000
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.isNavigationBarHidden = true
ecoMapButton.image = UIImage(systemName: "plus.circle")
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.isNavigationBarHidden = false
middleMapButton.image = UIImage(systemName: "mappin.circle")
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
checkLocationServices()
}
这是该标签栏项目的操作
func tabBar(_ tabBar: UITabBar,didSelect item: UITabBarItem) {
let annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2D(latitude: 41.881832,longitude: -87.623177)
mapView.addAnnotation(annotation)
}
这里有一些位置隐私行动
func setupLocationManager() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
}
func centerViewOnUserLocation() {
if let location = locationManager.location?.coordinate {
let region = MKCoordinateRegion.init(center: location,latitudinalMeters: regionInMeters,longitudinalMeters: regionInMeters)
mapView.setRegion(region,animated: true)
}
}
func checkLocationServices() {
if CLLocationManager.locationServicesEnabled() {
setupLocationManager()
checkLocationAuthorization()
} else {
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。