如何使 UWP 中的地理位置检索过程更快?
How to make geo location retrieval process faster in UWP?
我正在使用 Geolocator class 在 UWP 应用程序中查找设备的当前位置。位置检索过程在我的计算中运行得非常快。但是当我尝试 运行 真实设备中的同一个应用程序时,设备检索过程大约需要 30 秒。
我正在使用以下代码片段:
var accessStatus = await Geolocator.RequestAccessAsync();
if (accessStatus == GeolocationAccessStatus.Allowed)
{
Geolocator geolocator = new Geolocator
{
DesiredAccuracyInMeters = 500,
DesiredAccuracy = PositionAccuracy.High
};
Geoposition pos = await geolocator.GetGeopositionAsync()
}
如何在我的设备中加快此过程?
已经尝试将 DesiredAccuracyInMeters 值增加到 2000,但没有发现任何改进。提前致谢。
如果你检查documentation,你可以看到当你同时设置DesiredAccuracy
和DesiredAccuracyInMeters
时,最后一组优先:
When neither DesiredAccuracyInMeters nor DesiredAccuracy are set, your app will use an accuracy setting of 500 meters (which corresponds to the DesiredAccuracy setting of Default). Setting DesiredAccuracy to Default or High indirectly sets DesiredAccuracyInMeters to 500 or 10 meters, respectively. When your app sets both DesiredAccuracy and DesiredAccuracyInMeters, your app will use whichever accuracy value was set last.
因此,因为您将 DesiredAccuracy
设置为 High
,所以您实际上覆盖了仪表设置。为了加快搜索速度,请不要设置 High
精度,只设置米值。
我会补充 Martin 的问题,你应该先使用缓存的位置,然后使用 GetPositionAsync
,你应该通过这种方式更快地定位用户:
var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 500;
//Check if we have a cached position
var loc = await locator.GetLastKnownLocationAsync ();
if ( loc != null )
{
CurrentPosition = new Position (loc.Latitude, loc.Longitude);
}
if ( !locator.IsGeolocationAvailable || !locator.IsGeolocationEnabled )
{
return;
}
//and if not we get a new one
var def = await locator.GetPositionAsync (TimeSpan.FromSeconds (10), null, true);
CurrentPosition = new Position (def.Latitude, def.Longitude);
我正在使用 Geolocator class 在 UWP 应用程序中查找设备的当前位置。位置检索过程在我的计算中运行得非常快。但是当我尝试 运行 真实设备中的同一个应用程序时,设备检索过程大约需要 30 秒。 我正在使用以下代码片段:
var accessStatus = await Geolocator.RequestAccessAsync();
if (accessStatus == GeolocationAccessStatus.Allowed)
{
Geolocator geolocator = new Geolocator
{
DesiredAccuracyInMeters = 500,
DesiredAccuracy = PositionAccuracy.High
};
Geoposition pos = await geolocator.GetGeopositionAsync()
}
如何在我的设备中加快此过程?
已经尝试将 DesiredAccuracyInMeters 值增加到 2000,但没有发现任何改进。提前致谢。
如果你检查documentation,你可以看到当你同时设置DesiredAccuracy
和DesiredAccuracyInMeters
时,最后一组优先:
When neither DesiredAccuracyInMeters nor DesiredAccuracy are set, your app will use an accuracy setting of 500 meters (which corresponds to the DesiredAccuracy setting of Default). Setting DesiredAccuracy to Default or High indirectly sets DesiredAccuracyInMeters to 500 or 10 meters, respectively. When your app sets both DesiredAccuracy and DesiredAccuracyInMeters, your app will use whichever accuracy value was set last.
因此,因为您将 DesiredAccuracy
设置为 High
,所以您实际上覆盖了仪表设置。为了加快搜索速度,请不要设置 High
精度,只设置米值。
我会补充 Martin 的问题,你应该先使用缓存的位置,然后使用 GetPositionAsync
,你应该通过这种方式更快地定位用户:
var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 500;
//Check if we have a cached position
var loc = await locator.GetLastKnownLocationAsync ();
if ( loc != null )
{
CurrentPosition = new Position (loc.Latitude, loc.Longitude);
}
if ( !locator.IsGeolocationAvailable || !locator.IsGeolocationEnabled )
{
return;
}
//and if not we get a new one
var def = await locator.GetPositionAsync (TimeSpan.FromSeconds (10), null, true);
CurrentPosition = new Position (def.Latitude, def.Longitude);