我想知道是否有人可能知道如何使Mapbox注释能够在某个位置显示当前位置信息。有点像在Apple的地图中点击一个引脚或丢弃它然后显示位置名称或地址。我有丢弃引脚的代码,但之后我不知道如何让它显示当前位置的信息。感谢您的反馈意见。
import UIKit
import CoreLocation
import Mapbox
class SecondViewController: UIViewController, CLLocationManagerDelegate, MGLMapViewDelegate {
@IBOutlet var mapView: MGLMapView!
let manager = CLLocationManager()
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestWhenInUseAuthorization()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func markStuff(_ sender: Any) {
manager.startUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations[0]
let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
mapView.setCenter(center, zoomLevel: 15, animated: true)
let annotation = MGLPointAnnotation()
annotation.coordinate = location.coordinate
self.mapView.addAnnotation(annotation)
manager.stopUpdatingLocation()
}
}