12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Web;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using MySystem.Models;
- using Library;
- namespace MySystem.Areas.Admin.Controllers
- {
- public class BaseController : Controller
- {
- public WebCMSEntities db = new WebCMSEntities();
- public string Host = Library.ConfigurationManager.AppSettings["Host"].ToString();
- public BaseController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting)
- {
- }
- #region 两点距离
- public double GetDistanceNumber(string start, string end)
- {
- if (!string.IsNullOrEmpty(start) && !string.IsNullOrEmpty(end))
- {
- string[] startpos = start.Split(',');
- string[] endpos = end.Split(',');
- double lng1 = double.Parse(startpos[0]);
- double lat1 = double.Parse(startpos[1]);
- double lng2 = double.Parse(endpos[0]);
- double lat2 = double.Parse(endpos[1]);
- double radLat1 = rad(lat1);
- double radLat2 = rad(lat2);
- double a = radLat1 - radLat2;
- double b = rad(lng1) - rad(lng2);
- 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)));
- s = s * EARTH_RADIUS;
- s = Math.Round(s * 10000) / 10000;
- return s;
- }
- return 10000000;
- }
- private double rad(double d)
- {
- return d * Math.PI / 180.0;
- }
- private double EARTH_RADIUS = 6378.137;
- #endregion
-
- }
- }
|