BaseController.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 string JavaHost = Library.ConfigurationManager.AppSettings["JavaHost"].ToString();
  21. public BaseController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting)
  22. {
  23. }
  24. #region 两点距离
  25. public double GetDistanceNumber(string start, string end)
  26. {
  27. if (!string.IsNullOrEmpty(start) && !string.IsNullOrEmpty(end))
  28. {
  29. string[] startpos = start.Split(',');
  30. string[] endpos = end.Split(',');
  31. double lng1 = double.Parse(startpos[0]);
  32. double lat1 = double.Parse(startpos[1]);
  33. double lng2 = double.Parse(endpos[0]);
  34. double lat2 = double.Parse(endpos[1]);
  35. double radLat1 = rad(lat1);
  36. double radLat2 = rad(lat2);
  37. double a = radLat1 - radLat2;
  38. double b = rad(lng1) - rad(lng2);
  39. 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)));
  40. s = s * EARTH_RADIUS;
  41. s = Math.Round(s * 10000) / 10000;
  42. return s;
  43. }
  44. return 10000000;
  45. }
  46. private double rad(double d)
  47. {
  48. return d * Math.PI / 180.0;
  49. }
  50. private double EARTH_RADIUS = 6378.137;
  51. #endregion
  52. }
  53. }