BaseController.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using System.Web;
  8. using Microsoft.AspNetCore.Mvc;
  9. using Microsoft.AspNetCore.Http;
  10. using Microsoft.Extensions.Logging;
  11. using Microsoft.Extensions.Options;
  12. using MySystem.Models;
  13. using Library;
  14. namespace MySystem.Areas.Admin.Controllers
  15. {
  16. public class BaseController : Controller
  17. {
  18. public WebCMSEntities db = new WebCMSEntities();
  19. public string Host = Library.ConfigurationManager.AppSettings["Host"].ToString();
  20. public BaseController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting)
  21. {
  22. }
  23. #region 两点距离
  24. public double GetDistanceNumber(string start, string end)
  25. {
  26. if (!string.IsNullOrEmpty(start) && !string.IsNullOrEmpty(end))
  27. {
  28. string[] startpos = start.Split(',');
  29. string[] endpos = end.Split(',');
  30. double lng1 = double.Parse(startpos[0]);
  31. double lat1 = double.Parse(startpos[1]);
  32. double lng2 = double.Parse(endpos[0]);
  33. double lat2 = double.Parse(endpos[1]);
  34. double radLat1 = rad(lat1);
  35. double radLat2 = rad(lat2);
  36. double a = radLat1 - radLat2;
  37. double b = rad(lng1) - rad(lng2);
  38. double s = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(a / 2), 2) + Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Pow(Math.Sin(b / 2), 2)));
  39. s = s * EARTH_RADIUS;
  40. s = Math.Round(s * 10000) / 10000;
  41. return s;
  42. }
  43. return 10000000;
  44. }
  45. private double rad(double d)
  46. {
  47. return d * Math.PI / 180.0;
  48. }
  49. private double EARTH_RADIUS = 6378.137;
  50. #endregion
  51. }
  52. }