我有地理定位的应用程序,我检索当前的地理位置,但应用程序上的显示非常慢......
构造函数:
public TaskGeo()
{
InitializeComponent();
_geolocator = new Geolocator();
_geolocator.DesiredAccuracy = PositionAccuracy.High;
_geolocator.MovementThreshold = 100;
_geolocator.PositionChanged += _geolocator_PositionChanged;
_geolocator.StatusChanged += _geolocator_StatusChanged;
if (_geolocator.LocationStatus == PositionStatus.Disabled)
this.DisplayNeedGPS();
}
应用程序上显示的代码:
void _geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
// saving and display of the position
App.RootFrame.Dispatcher.BeginInvoke(() =>
{
this._CurrentPosition = args.Position;
this.lblLon.Text = "Lon: " + this._CurrentPosition.Coordinate.Longitude;
this.lblLat.Text = "Lat: " + this._CurrentPosition.Coordinate.Latitude;
this.LocationChanged(this._CurrentPosition.Coordinate.Longitude, this._CurrentPosition.Coordinate.Latitude);
});
}
查询代码:
private void LocationChanged(double lat, double lon)
{
ReverseGeocodeQuery rgq = new ReverseGeocodeQuery();
rgq.GeoCoordinate = new GeoCoordinate(lat, lon);
rgq.QueryCompleted += rgq_QueryCompleted;
rgq.QueryAsync();
}
如何改进代码以更快地显示位置?提前谢谢!
答案 0 :(得分:3)
获取此类信息基本上非常慢。引用伟大的路易斯C.K.“这将是空间,给它一秒钟”。因为您已指定PositionAccuracy.High
,这意味着必须使用相对较慢的GPS找到该位置,而不是使用本地Wi-Fi或手机信号塔等任何更快速的后备方法。
您可以降低对整体精确度的要求,或者最初请求较低的准确度,然后在GPS信息可用后进行优化。第二种选择更好。如果您查看地图应用程序,他们通常会通过向您显示您的位置然后在获取GPS锁定后进行改进来实现此目的。