Esempio n. 1
0
		/// <summary>
		///  format latitude,longtitude to 4 fractional ditigal double;
		/// </summary>
		/// <param name="objLatLon"></param>
		/// <returns></returns>
		public static LatLon GetFormatedLatLon(LatLon objLatLon)
		{
			///按照经纬度查询
			if (objLatLon.Lat > 90 || objLatLon.Lat < -90 || objLatLon.Lon > 180 || objLatLon.Lon < -180)
			{
				throw new ArgumentException("经纬度超限");
			}

			LatLon objRsltLatLon = new LatLon();


			objRsltLatLon.Lat = Math.Round(objLatLon.Lat, 6);
			objRsltLatLon.Lon = Math.Round(objLatLon.Lon, 6);

			return objRsltLatLon;
		}
Esempio n. 2
0
		/// <summary>
		/// 根据两点的经纬度计算两点距离
		/// 可参考:通过经纬度计算距离的公式 http://www.storyday.com/html/y2009/2212_according-to-latitude-and-longitude-distance-calculation-formula.html
		/// </summary>
		/// <param name="src">A点维度</param>        
		/// <param name="dest">B点经度</param>
		/// <returns></returns>
		public static double GetDistance(LatLon src, LatLon dest)
		{
			if (Math.Abs(src.Lat) > 90 || Math.Abs(dest.Lat) > 90 || Math.Abs(src.Lon) > 180 || Math.Abs(dest.Lon) > 180)
				throw new ArgumentException("经纬度信息不正确!");

			double latDis = src.RadLat - dest.RadLat;
			double lonDis = src.RadLon - dest.RadLon;

			double s = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(latDis / 2), 2) + Math.Cos(src.RadLat) * Math.Cos(dest.RadLat) * Math.Pow(Math.Sin(lonDis / 2), 2)));

			s = s * LatLon.EARTH_RADIUS / 1000;
			s = Math.Round(s * 10000) / 10000;

			return s;
		}
Esempio n. 3
0
		/// <summary>
		/// 已知点A经纬度,根据B点据A点的距离,和方位,求B点的经纬度
		/// </summary>
		/// <param name="longitude">已知点A经度</param>
		/// <param name="latitude">已知点A纬度</param>
		/// <param name="distance">B点到A点的距离</param>
		/// <param name="angle">B点相对于A点的方位,12点钟方向为零度,角度顺时针增加</param>
		/// <returns>B点的经纬度坐标</returns>
		public static LatLon GetLatLon(double longitude, double latitude, double distance, double angle)
		{
			LatLon a = new LatLon(latitude, longitude);
			return GetLatLon(a, distance, angle);
		}
Esempio n. 4
0
		private static bool IsLongLatValid(LatLon objLatLon)
		{
			if (objLatLon.Lat > 90 || objLatLon.Lat < -90 || objLatLon.Lon > 180 || objLatLon.Lon < -180)
				return false;
			return true;
		}
Esempio n. 5
0
		public static LatLon GetRightLowerCornerLatLon(LatLon a, double dDistanceInKilometer)
		{
			return GetLatLon(a, GetRealDistance(dDistanceInKilometer), 135);
		}
Esempio n. 6
0
		public static LatLon GetLeftUpperCornerLatLon(LatLon a, double dDistanceInKilometer)
		{
			return GetLatLon(a, GetRealDistance(dDistanceInKilometer), 315);
		}
Esempio n. 7
0
		public static LatLon GetRightLowerCornerLatLon(double dLongitude, double dLatitude, double dDistanceInKilometer)
		{
			LatLon a = new LatLon(dLatitude, dLongitude);
			return GetLatLon(a, GetRealDistance(dDistanceInKilometer), 135);
		}
Esempio n. 8
0
		/// <summary>
		/// 已知点A经纬度,根据B点据A点的距离,和方位,求B点的经纬度
		/// </summary>
		/// <param name="a">已知点A</param>
		/// <param name="distance">B点到A点的距离 </param>
		/// <param name="angle">B点相对于A点的方位,12点钟方向为零度,角度顺时针增加</param>
		/// <returns>B点的经纬度坐标</returns>
		public static LatLon GetLatLon(LatLon a, double distance, double angle)
		{
			//if (distance > 0)
			//{
			//    distance *= Math.Sqrt(2);
			//}
			if (!IsLongLatValid(a))
				return null;
			double dx = distance * 1000 * Math.Sin(angle * Math.PI / 180);
			double dy = distance * 1000 * Math.Cos(angle * Math.PI / 180);

			double lon = (dx / a.Ed + a.RadLon) * 180 / Math.PI;
			double lat = (dy / a.Ec + a.RadLat) * 180 / Math.PI;

			LatLon b = new LatLon(lat, lon);
			return b;
		}
Esempio n. 9
0
		/// <summary>
		/// 根据两点的经纬度计算两点距离
		/// 可参考:通过经纬度计算距离的公式 http://www.storyday.com/html/y2009/2212_according-to-latitude-and-longitude-distance-calculation-formula.html
		/// </summary>
		/// <param name="lat1">A点维度</param>
		/// <param name="lon1">A点经度</param>
		/// <param name="lat2">B点维度</param>
		/// <param name="lon2">B点经度</param>
		/// <returns></returns>
		public static double GetDistance(double lat1, double lon1, double lat2, double lon2)
		{
			LatLon src = new LatLon(lat1, lon1);
			LatLon dest = new LatLon(lat2, lon2);
			return GetDistance(src, dest);
		}