更正PositionWithLocationProvider中的NullReferenceException?

时间:2017-10-06 15:54:26

标签: c# unity3d mapbox foursquare arkit

我正在处理How to build an Augmented Reality App using the Foursquare API + Mapbox + ARKit示例项目并在运行时收到以下错误:

NullReferenceException: Object reference not set to an instance of an object
Mapbox.Examples.LocationProvider.PositionWithLocationProvider.get_LocationProvider () (at Assets/PositionWithLocationProvider.cs:42)
Mapbox.Examples.LocationProvider.PositionWithLocationProvider.Start () (at Assets/PositionWithLocationProvider.cs:63)

看一下PositionWithLocationProvider.cs,这就是问题所在:

ILocationProvider _locationProvider;
public ILocationProvider LocationProvider
{
  private get
  {
    if (_locationProvider == null)
    {
      _locationProvider = _useTransformLocationProvider ?
      LocationProviderFactory.Instance.TransformLocationProvider : LocationProviderFactory.Instance.DefaultLocationProvider; // Line 42
    }

    return _locationProvider;
  }
  set
  {
    if (_locationProvider != null)
    {
      _locationProvider.OnLocationUpdated -= LocationProvider_OnLocationUpdated;

    }
    _locationProvider = value;
    _locationProvider.OnLocationUpdated += LocationProvider_OnLocationUpdated;
  }
}
Vector3 _targetPosition;

void Start()
{
  LocationProvider.OnLocationUpdated += LocationProvider_OnLocationUpdated; // Line 63
  _map.OnInitialized += () => _isInitialized = true;
}

(完整文件可在this gist中找到。)

我知道此时_locationProvider为空,但我不确定为什么LocationProviderFactory.Instance会被轰炸。任何帮助将不胜感激!

0 个答案:

没有答案