提取经度和纬度之后,我尝试使用它们来获取当前的速度,但是我只能得到0(我在公共汽车和火车上都尝试过)
我尝试获取当前位置,并将其保存在两个变量中,然后使用“延迟”函数在1秒后获取第二个位置,然后计算出这两个点之间的距离后来计算了我的速度。
I-这是获取我的距离的函数:
public double distance_on_geoid(double lat1, double lon1, double lat2, double lon2)
{
double x = (lon2 - lon1)*(lon2 - lon1);
double y = (lat2 - lat1)* (lat2 - lat1);
double z = 6371 * Math.PI * 2;
double w = z / 360;
double xx = x + y;
double zz = xx * z;
double distance = Math.Sqrt(zz);
return distance;
}
II-这是计算我的速度的函数:
public double GetVitesse(double distance)
{
double time_s = 0.27;
double speed_kph = distance / time_s;
return speed_kph;
}
III-这就是我所谓的函数:
var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 50;
var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(1));
while (true)
{
double lat1 = position.Latitude;
double long1 = position.Longitude;
await Task.Delay(1000);
double lat2 = position.Latitude;
double long2 = position.Longitude;
double dist = distance_on_geoid(lat1, long1, lat2, long2);
double vits = GetVitesse(dist);
vitesse.Text = vits.ToString();
}
我希望在标签vitesse
中显示速度。