我需要为我的应用做这个,但我不确定如何。目前我正在尝试使用Geolocator和Timer实现它。
答案 0 :(得分:1)
借助这些方法比较当前存储位置以检测移动
public const double EARTH_RADIUS_M = 6371000
private static double ToRad(double val)
{
return val * (Math.PI / 180);
}
public static double GetDistanceM(double lat0, double lng0, double lat1, double lng1)
{
double dLat = ToRad(lat1 - lat0);
double dLon = ToRad(lng1 - lng0);
double a = Math.Pow(Math.Sin(dLat / 2), 2) +
Math.Cos(ToRad(lat0)) * Math.Cos(ToRad(lat1)) *
Math.Pow(Math.Sin(dLon / 2), 2);
double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
double distance = EARTH_RADIUS_M * c;
return distance;
}
Windows 10的注意事项:
private async void StartLocationExtensionSession()
{
session = new ExtendedExecutionSession();
session.Description = "Location Tracker";
session.Reason = ExtendedExecutionReason.LocationTracking;
var result = await session.RequestExtensionAsync();
}
Windows Phone 8的注意事项:
https://msdn.microsoft.com/en-us/library/windows/apps/jj662935(v=vs.105).aspx