Location.getProvider 始终返回“fused”而不是 GPS 或网络

问题描述 投票:0回答:2

我正在使用融合位置 API:

        locationrequest = LocationRequest.create();
        locationrequest.setInterval(interval);
        locationrequest.setFastestInterval(interval);
        locationrequest.setSmallestDisplacement(0);

        locationrequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

        LocationServices.FusedLocationApi.requestLocationUpdates(locationClient, locationrequest, this);

每当我获得位置时,我都会执行 loc.getProvider 并且总是得到字符串“Fused”。

我期待网络与 GPS 或其他一些指示。

有什么想法吗?

android android-location
2个回答
1
投票

这是 FusedLocationApi 的预期行为 - 它结合了服务以减少功耗以及出于各种其他原因。

如果您需要使用特定的提供程序,您需要 http://developer.android.com/reference/android/location/package-summary.html

正如该页面所说,这不是获取位置的推荐方法。

如果您有兴趣处理返回位置的准确性,最好逐个更新地执行此操作 - 使用 Location.getAccuracy()


0
投票

我在 MAUI 上得到的 GPS 结果非常糟糕。它会到处跳,有时跳到一英里外。我必须使用旧方法(来自 Xamarin)才能获得良好的 GPS 读数。我还必须强制提供者字符串为“gps”,否则它会选择那个糟糕的融合提供者,这是准确性最差的。这是我正在处理的 MAUI 应用程序中的 MainActivity.cs 文件。它只是在准备好后立即读取位置,并构建一个新的 Microsoft.Maui.Devices.Sensors.Location() 对象,并使用位置管理器返回的 Android.Locations.Location 对象中的字段填充它。

public class MainActivity : MauiAppCompatActivity, ILocationListener
{
    private LocationManager MyLocMgr;
    private string LocationProvider;

    protected override void OnCreate(Bundle bundle)
    {
        //Initialize android.
        base.OnCreate(bundle);


        #region Location.

        // Start listening to the GPS if it can be reached.
        MyLocMgr = GetSystemService(LocationService) as LocationManager;
        MyLocMgr.RequestLocationUpdates("gps", 1000, 0.0001F, this);
 
        #endregion
    }


    public void OnLocationChanged(Android.Locations.Location location)
    {
        MainPage.MyCurrentLocation = new Microsoft.Maui.Devices.Sensors.Location()
        {
            Latitude = location.Latitude,
            Longitude = location.Longitude,
            Altitude = location.Altitude,
            Accuracy = location.Accuracy,
            VerticalAccuracy = location.VerticalAccuracyMeters,
            Timestamp = new DateTimeOffset(DateTime.UtcNow)
        };
    }

    public void OnProviderDisabled(string provider)
    {

    }

    public void OnProviderEnabled(string provider)
    {

    }

    public void OnStatusChanged(string provider, [GeneratedEnum] Availability status, Bundle extras)
    {

    }
}
© www.soinside.com 2019 - 2024. All rights reserved.