Xamarin Essentials的地理定位功能定位结果错误

Xamarin Essentials的地理定位功能定位结果错误,xamarin,geolocation,Xamarin,Geolocation,我在我的应用程序中使用Xamarin Essentials的地理位置功能,作为一直运行的前台服务。我注意到,在一些设备上,我有时会得到离实际位置很远的位置,看起来像这样(标记的位置离实际位置很远): 公共异步任务运行(CancellationToken令牌) { 等待任务。运行(异步()=>{ 当(!停止) { token.ThrowIfCancellationRequested(); 尝试 { 等待任务。延迟(2000); var请求=新地理定位请求(geolocationaccurity.B

我在我的应用程序中使用Xamarin Essentials的地理位置功能,作为一直运行的前台服务。我注意到,在一些设备上,我有时会得到离实际位置很远的位置,看起来像这样(标记的位置离实际位置很远):

公共异步任务运行(CancellationToken令牌)
{
等待任务。运行(异步()=>{
当(!停止)
{
token.ThrowIfCancellationRequested();
尝试
{
等待任务。延迟(2000);
var请求=新地理定位请求(geolocationaccurity.Best);
var location=await Geolocation.GetLocationAsync(请求);
如果(位置!=null)
{
var消息=新位置消息
{
纬度=位置。纬度,
经度=位置。经度
};
Device.beginInvokeMainThread(()=>
{
发送(消息,“位置”);
});
}
}
捕获(例外情况除外)
{
Device.beginInvokeMainThread(()=>
{
var errormessage=新位置errormessage();
MessagingCenter.Send(errormessage,“LocationError”);
});
}
}
返回;
},代币);
}

请不要将代码或错误作为图像发布。你需要编辑你的问题,以包含内联代码,格式为文本。我不认为这是一个软件问题-地理定位仪只是报告它从设备上获得的信息。正如Jason所说,地理定位用于获取设备上的GPS信息。我在模拟器中设置了不同的地址,一切正常。尝试检查设备中的GPS信息是否正确。
public async Task Run(CancellationToken token)
    {
        await Task.Run(async () => {
            while (!stopping)
            {
                token.ThrowIfCancellationRequested();
                try
                {
                    await Task.Delay(2000);
                    var request = new GeolocationRequest(GeolocationAccuracy.Best);
                    var location = await Geolocation.GetLocationAsync(request);
                    if (location != null)
                    {
                        var message = new LocationMessage
                        {
                            Latitude = location.Latitude,
                            Longitude = location.Longitude
                        };
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            MessagingCenter.Send<LocationMessage>(message, "Location");
                        });
                    }
                }
                catch (Exception ex)
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        var errormessage = new LocationErrorMessage();
                        MessagingCenter.Send<LocationErrorMessage>(errormessage, "LocationError");
                    });
                }
            }
            return;
        }, token);
    }