如何调用Mapbox LocationManager的有效位置代理方法(如didUpdateLocations)
Mapbox SDK:获取位置与航向更新的替代方案疑问
之前可直接通过LocationManager访问的didUpdateLocations、didUpdateHeading这类位置代理方法,现在在Mapbox代码中被标记为废弃且不再生效,相关代码如下:
// These methods must remain to avoid breaking the API, but their implementation has been moved // to `LocationProducer`. They should be fully removed in the next major version. extension `LocationProducer`: LocationProviderDelegate { /// :nodoc: /// Deprecated. This method no longer has any effect. public func locationProvider(_ provider: LocationProvider, didUpdateLocations locations: [CLLocation]) {} /// :nodoc: /// Deprecated. This method no longer has any effect. public func locationProvider(_ provider: LocationProvider, didUpdateHeading newHeading: CLHeading) {} /// :nodoc: /// Deprecated. This method no longer has any effect. public func locationProvider(_ provider: LocationProvider, didFailWithError error: Error) {} /// :nodoc: /// Deprecated. This method no longer has any effect. public func locationProviderDidChangeAuthorization(_ provider: LocationProvider) {} }
需要说明的是,LocationProducer是私有属性,无法直接操作。
我猜测可以通过Mapbox提供的以下方法重写LocationProvider:
public func overrideLocationProvider(with customLocationProvider: LocationProvider) { locationProducer.locationProvider = customLocationProvider }
或者自行实现带有func setDelegate(_ delegate: LocationProviderDelegate)方法的自定义代理,但还未尝试这些方案,想确认是否存在更简便的处理方式,求熟悉Mapbox SDK逻辑的开发者解答。
内容的提问来源于stack exchange,提问作者13thApostle
相关产品推荐
相关产品推荐

