Esempio n. 1
0
        /// <summary>
        ///Calculates the distance between two lat/lng's in miles or meters.
        /// </summary>
        /// <param name="ll2">Second lat,lng position to calculate distance to.</param>
        /// <param name="lUnits">Units to calculate distance, defaults to miles</param>
        /// <returns>Returns the distance in meters or miles</returns>
        public double ArcDistance(LatLng ll2, DistanceUnits lUnits)
        {
            LatLng ll1 = Normalize();

            ll2 = ll2.Normalize();

            double lat1 = ll1.GetLat(), lng1 = ll1.GetLng();
            double lat2 = ll2.GetLat(), lng2 = ll2.GetLng();

            // Check for same position
            if (lat1 == lat2 && lng1 == lng2)
            {
                return(0.0);
            }

            // Get the m_dLongitude difference. Don't need to worry about
            // crossing 180 since cos(x) = cos(-x)
            double dLon = lng2 - lng1;

            double a    = Radians(90.0 - lat1);
            double c    = Radians(90.0 - lat2);
            double cosB = (Math.Cos(a) * Math.Cos(c))
                          + (Math.Sin(a) * Math.Sin(c) * Math.Cos(Radians(dLon)));

            double radius = (lUnits == DistanceUnits.MILES) ? 3963.205 /* MILERADIUSOFEARTH */ : 6378.160187
                            /* KMRADIUSOFEARTH */;

            // Find angle subtended (with some bounds checking) in radians and
            // multiply by earth radius to find the arc distance
            if (cosB < -1.0)
            {
                return(MathHelper.PI * radius);
            }

            if (cosB >= 1.0)
            {
                return(0);
            }

            return(Math.Acos(cosB) * radius);
        }
Esempio n. 2
0
 public FloatLatLng(LatLng ll)
 {
     _lat = ll.GetLat();
     _lng = ll.GetLng();
 }
Esempio n. 3
0
 public override LatLng CalculateMidpoint(LatLng other)
 {
     return(new FloatLatLng((_lat + other.GetLat()) / 2.0, (_lng + other.GetLng()) / 2.0));
 }
Esempio n. 4
0
		public FloatLatLng(LatLng ll)
		{
			_lat = ll.GetLat();
			_lng = ll.GetLng();
		}
Esempio n. 5
0
		public override LatLng CalculateMidpoint(LatLng other)
		{
			return new FloatLatLng((_lat + other.GetLat()) / 2.0, (_lng + other.GetLng()) / 2.0);
		}
Esempio n. 6
0
		/// <summary>
		///Calculates the distance between two lat/lng's in miles or meters.
		/// </summary>
		/// <param name="ll2">Second lat,lng position to calculate distance to.</param>
		/// <param name="lUnits">Units to calculate distance, defaults to miles</param>
		/// <returns>Returns the distance in meters or miles</returns>
		public double ArcDistance(LatLng ll2, DistanceUnits lUnits)
		{
			LatLng ll1 = Normalize();
			ll2 = ll2.Normalize();

			double lat1 = ll1.GetLat(), lng1 = ll1.GetLng();
			double lat2 = ll2.GetLat(), lng2 = ll2.GetLng();

			// Check for same position
			if (lat1 == lat2 && lng1 == lng2)
				return 0.0;

			// Get the m_dLongitude difference. Don't need to worry about
			// crossing 180 since cos(x) = cos(-x)
			double dLon = lng2 - lng1;

			double a = Radians(90.0 - lat1);
			double c = Radians(90.0 - lat2);
			double cosB = (Math.Cos(a) * Math.Cos(c))
			              + (Math.Sin(a) * Math.Sin(c) * Math.Cos(Radians(dLon)));

			double radius = (lUnits == DistanceUnits.MILES) ? 3963.205 /* MILERADIUSOFEARTH */ : 6378.160187
				/* KMRADIUSOFEARTH */;

			// Find angle subtended (with some bounds checking) in radians and
			// multiply by earth radius to find the arc distance
			if (cosB < -1.0) return MathHelper.PI * radius;

			if (cosB >= 1.0) return 0;

			return Math.Acos(cosB) * radius;
		}