WinRT Geolocator始终返回相同的位置

时间:2013-06-23 12:27:31

标签: geolocation gps windows-runtime

我们的应用程序中的WinRT Geolocator有一个奇怪的行为。用户单击应用程序中的按钮以获取当前位置。第一次工作正常,但随后点击按钮返回相同的坐标,即使我们移动超过一公里也很难。

应用程序在ThinkPad上运行,我们安装了一个名为“GPS Satellite”的应用程序,如果我们切换到这个应用程序,获取坐标,然后返回我们的应用程序,Geolocator将返回正确的坐标。所以我们知道GPS工作正常,但似乎坐标保存在缓存中甚至很难我们设置了几毫秒的到期时间。

private async void ExecuteObtenirCoordGPSCommand()
        {      
            try
            {
                Geolocator geolocator = new Geolocator();
                geolocator.DesiredAccuracy = PositionAccuracy.High;
                // Make the request for the current position

                Geoposition pos = await geolocator.GetGeopositionAsync(new TimeSpan(0,0,0,0,200), new TimeSpan(0,0,5));


                Place.Latitude = pos.Coordinate.Latitude;
                Place.Longitude = pos.Coordinate.Longitude;
            }
            catch
            {
                GPSMsgErreur = "The GPS is unavailable";
            }
}

我们试图在方法GetGeopositionAsync上过期,但它没有解决问题。

我们试图将Geolocator var放在类级别,结果相同。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

不确定这是否是您的问题,但您使用的API标记在此帖子中已过时: http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.geocoordinate

尝试使用:

Place.Latitude = pos.Coordinate.Point.Position.Latitude;
Place.Longitude = pos.Coordinate.Point.Position.Longitude;

您也可以使用:

double someVar = pos.Coordinate.Accuracy

找出设备上的误差范围。可能是你距离你的第一个位置不远的地方,而你的第二个位置在误差范围内......

我还可以告诉您,我有一个使用Visual Studio 2013 Windows(WinRT)构建的软件,该软件使用您正在使用的相同对象在ThinkPad上运行,并且工作正常。 我和你之间的主要区别在于我使用上面显示的API并且我没有使用以下语句:

geolocator.DesiredAccuracy = PositionAccuracy.High;

而且我没有将任何参数传递给GetGeopositionAsync方法。

我希望这会有所帮助。 干杯,汉斯。