0

我很困惑为什么这是显示默认图像而不是纽约上空的蓝色圆形圆圈。对此以及何时使用默认图像的任何见解将不胜感激。

import UIKit
import Mapbox

class ViewController: UIViewController, MGLMapViewDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        setupMapview()
    }

    func setupMapview(){
        let mapView = MGLMapView(frame: view.bounds)
        mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        mapView.setCenter(CLLocationCoordinate2D(latitude: 40.74699, longitude: -73.98742), zoomLevel: 9, animated: false)
        view.addSubview(mapView)

        let annotation = MGLPointAnnotation()
        annotation.coordinate = CLLocationCoordinate2D(latitude: 40.77014, longitude: -73.97480)
        mapView.addAnnotation(annotation)

        mapView.delegate = self
    }


    func mapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? {
        print("CORDINATE")
        print(annotation.coordinate)
        if annotation is MGLPointAnnotation {
            print("SET\n\n\n")
            let av = RoundedAnnotationView(annotation: annotation, reuseIdentifier: "ResuseIdentifier")
            av.configure()
            return av
        }
        return nil
    }
}

class RoundedAnnotationView: MGLAnnotationView{
    func configure(){
        backgroundColor = .blue
        layer.cornerRadius = 24
        clipsToBounds = true
    }
}

输出: iPhone_Screen print_statements

4

2 回答 2

0

标准默认注释显示在 NY 中,因为这正是您在setupMapview. 如果您希望地图显示用户的位置,您必须告诉它这样做:

mapView.addAnnotation(annotation)

mapView.showsUserLocation = true // This needs to be set explicitly.

mapView.delegate = self

像往常一样,当您想要访问用户的位置时,您必须通过在以下位置插入正确的标志来请求许可info.plist

Privacy - Location When In Use Usage Description

以及某种解释性字符串:

"We'd like to track you with our satellite."

如果您在模拟器上运行您的应用程序,您可以创建一个自定义位置:

模拟器 -> 功能 -> 位置 -> 自定义位置...

于 2020-06-09T12:15:09.387 回答
0

地图完全加载后应添加注释。我有更详细的分步解决方案:https ://github.com/mapbox/mapbox-gl-native/issues/16492

于 2020-06-09T15:47:12.983 回答