private const double EARTH_RADIUS = 6378.137;//地球半径 private float CalcDistance(CityInfo m, Com.Aurora.AuWeather.Models.Location location) { var lat1 = Tools.DegreesToRadians(m.Location.Latitude); var lat2 = Tools.DegreesToRadians(location.Latitude); var a = lat1 - lat2; var b = Tools.DegreesToRadians(m.Location.Longitude) - Tools.DegreesToRadians(location.Longitude); var s = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(a / 2), 2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Pow(Math.Sin(b / 2), 2))); s *= EARTH_RADIUS; return((float)Math.Round(s * 10000) / 10000f); }
public static TimeSpan GetSet(Location geoPoint, DateTime desiredTime) { double sunset, glong, glat; int year, month, date; year = desiredTime.Year; month = desiredTime.Month; date = desiredTime.Day; glong = geoPoint.Longitude; glat = geoPoint.Latitude; sunset = result_set(UT_set(UTo, GHA(UTo, G_sun(t_century(days(year, month, date), UTo)), ecliptic_longitude(L_sun(t_century(days(year, month, date), UTo)), G_sun(t_century(days(year, month, date), UTo)))), glong, e(h, glat, sun_deviation(earth_tilt(t_century(days(year, month, date), UTo)), ecliptic_longitude(L_sun(t_century(days(year, month, date), UTo)), G_sun(t_century(days(year, month, date), UTo)))))), UTo, glong, glat, year, month, date); return new TimeSpan((int)(sunset / 15 + (DateTime.Now - DateTime.UtcNow).Hours), (int)(60 * (sunset / 15 + (DateTime.Now - DateTime.UtcNow).Hours - (int)(sunset / 15 + (DateTime.Now - DateTime.UtcNow).Hours))) - 1, 0); }