using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
namespace HZQR.Common
{
public class Pub
{
#region 方法 -> 获取get,post传参的值
///
/// 获取get,post传参的值
///
/// 参数名
/// 参数为空时的默认值
///
public static string Request(string key, string defaultValue = null)
{
var v = HttpContext.Current.Request.Form[key];
if (v == null)
{
v = HttpContext.Current.Request.QueryString[key];
}
return v ?? (defaultValue ?? string.Empty);
}
#endregion
#region 方法 -> 获取上个月第一天和最后一天
//获取上个月第一天
public static DateTime FirstDayOfPreviousMonth(DateTime datetime)
{
return datetime.AddDays(1 - datetime.Day).AddMonths(-1);
}
//获取上个月的最后一天
public static DateTime LastDayOfPrdviousMonth(DateTime datetime)
{
return datetime.AddDays(1 - datetime.Day).AddDays(-1);
}
#endregion
#region 方法 -> 计算距离
///
/// 计算两点位置的距离,返回两点的距离,单位:公里或千米
/// 该公式为GOOGLE提供,误差小于0.2米
///
/// 第一点纬度
/// 第一点经度
/// 第二点纬度
/// 第二点经度
/// 返回两点的距离,单位:公里或千米
public static double GetDistance(double lat1, double lng1, double lat2, double lng2)
{
//地球半径,单位米
double EARTH_RADIUS = 6378137;
double radLat1 = Rad(lat1);
double radLng1 = Rad(lng1);
double radLat2 = Rad(lat2);
double radLng2 = Rad(lng2);
double a = radLat1 - radLat2;
double b = radLng1 - radLng2;
double result = 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))) * EARTH_RADIUS;
return result / 1000;
}
///
/// 经纬度转化成弧度
///
///
///
private static double Rad(double d)
{
return (double)d * Math.PI / 180d;
}
#endregion
}
}