如何使用当前位置信息显示Mapbox注释

时间:2017-10-14 14:20:04

标签: ios swift dictionary annotations mapbox

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

}

1 个答案:

答案 0 :(得分:0)

您需要反向地理编码注释的坐标。 Mapbox iOS SDK不提供此功能,但我们提供了一个名为MapboxGeocoder.swift的库。