Swift 从不调用MapBox didUpdateUserLocation

Swift 从不调用MapBox didUpdateUserLocation,swift,mapbox,Swift,Mapbox,我正在尝试使用MapBox响应iOS应用程序中用户位置的更改,但未调用didUpdateUserLocation。为什么没有调用didUpdateUserLocation ViewController.swift import UIKit import Mapbox class ViewController: UIViewController, MGLMapViewDelegate { @IBOutlet weak var upButton: UIButton! overr

我正在尝试使用MapBox响应iOS应用程序中用户位置的更改,但未调用
didUpdateUserLocation
。为什么没有调用
didUpdateUserLocation

ViewController.swift

import UIKit
import Mapbox

class ViewController: UIViewController, MGLMapViewDelegate  {
    @IBOutlet weak var upButton: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
        let styleURL = NSURL(string: "mapbox://styles/jmeyers919/cj8w00yxvfrqr2rpehxd47up1") // MGLStyle.darkStyleURL()
        let mapView = MGLMapView(frame: view.bounds, styleURL: styleURL as URL?)
        mapView.delegate = self
        mapView.logoView.isHidden = true
        mapView.attributionButton.isHidden = true
        mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        // Note that we have changed the center coordinate to New York City for this guide
        // mapView.setCenter(CLLocationCoordinate2D(latitude: 44.0475276, longitude: -123.08927319), zoomLevel: 16, animated: false)
        mapView.userTrackingMode = .follow
        mapView.showsUserLocation = true
        view.addSubview(mapView)
        self.view.bringSubview(toFront: self.upButton)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func mapView(mapView: AnyObject!, didUpdateUserLocation userLocation: AnyObject!) {
      print("didUpdateUserLocation")
    }
}

showsUserLocation
属性设置为
YES
时,调用此方法 每当地图视图收到新位置更新时。这种方法也是可行的 如果地图视图的用户跟踪模式设置为
MGLUserTrackingModeFollowWithHeading
并且如果设置了标题,则标题会更改 转到
MGLUserTrackingModeFollowWithCourse
,课程将更改

如果应用程序当前正在后台运行,则不会调用此方法。如果要在中运行时接收位置更新
后台,您必须使用核心位置框架。

您是否请求授权跟踪用户位置?@TNguyen我想我不需要。Mapbox正在显示正确的用户位置(带有
showsUserLocation
),并提示用户输入权限,因此我假设Mapbox正在发出请求。