如何让地图框注释显示当前位置信息



我想知道是否有人知道如何使 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()
    }
}

您需要对注记的坐标进行反向地理编码。Mapbox iOS SDK不提供开箱即用的功能,但我们提供了一个名为MapboxGeocoder.swift的库。

最新更新