Location.getBearing始终为0.0

时间:2012-02-14 17:22:31

标签: android gps

我正在使用LocationListener并且返回的位置始终具有方位为0.0

还有什么我需要做的吗?

我还注意到,在4.0.3更新时,我很少报告速度。现在我只是获得位置和准确性/提升

public void onLocationChanged(Location loc)
    {
        Log.d(LOG_TAG, "onLocationChanged");

        Position position  = new Position();

            position.PositionGKey = UUID.randomUUID();
            position.GPSTime = new Date(loc.getTime());
            position.DeviceTime = new Date();
            position.Latitude = loc.getLatitude();
            position.Longitude = loc.getLongitude();
            position.Altitude = loc.getAltitude();
            position.Speed = loc.hasSpeed() ? loc.getSpeed() * 2.23693629 : 0;
            position.Accuracy = (int)loc.getAccuracy();
            position.Bearing = loc.hasBearing() ? loc.getBearing() : 0;

            // There was cases with speed reported 1000+. Just make it real here, round of obvious errors.
            if (position.Speed > 120)
            {
                position.Speed = 0.0;
            }

            PositionData.InsertPosition(getApplicationContext(), position);

    }

1 个答案:

答案 0 :(得分:0)

使用GPS提供商时,轴承通常不会更新/返回,除非设备物理移动并获得速度(检查getSpeed())。在实践中,速度超过1米/秒应该产生精确的轴承。我还发现我不得不偶尔轮询并检查GPS提供商的最后一个已知位置并抓住它的更新轴承以获得正确的读数。