【问题标题】:How do I have Mapbox annotations show up with current location information如何让 Mapbox 注释显示当前位置信息
【发布时间】:2018-03-26 12:21:16
【问题描述】:

我想知道是否有人知道如何使 Mapbox 注释能够在放置在某个位置后显示当前位置信息。有点像苹果的地图,当你点击一个图钉或放下一个图钉,然后它会显示位置名称或地址。我有被丢弃的图钉的代码,但之后我不知道如何让它显示当前位置的信息。提前感谢您的反馈。

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()
    }

}

【问题讨论】:

    标签: ios swift dictionary annotations mapbox


    【解决方案1】:

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

    【讨论】:

    • 谢谢我已经尝试过了,但我不知道如何导入它,因为当我使用可可豆荚并完成所有操作然后打开 Xcode 并输入 import MapboxGeocoder 它告诉我不存在这样的模块...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-03
    • 1970-01-01
    • 2016-10-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多