/// <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; }
public FloatLatLng(LatLng ll) { _lat = ll.GetLat(); _lng = ll.GetLng(); }
public override LatLng CalculateMidpoint(LatLng other) { return new FloatLatLng((_lat + other.GetLat()) / 2.0, (_lng + other.GetLng()) / 2.0); }
public FixedLatLng(LatLng ll) { _lat = ll.GetFixedLat(); _lng = ll.GetFixedLng(); }
public override LatLng CalculateMidpoint(LatLng other) { return new FixedLatLng((_lat + other.GetFixedLat())/2, (_lng + other.GetFixedLng())/2); }
/// <summary> /// Calculates the distance between two lat/lng's in miles. /// </summary> /// <param name="latLng">The lat lng.</param> /// <returns>Returns the distance in miles</returns> public double ArcDistance(LatLng ll2) { return ArcDistance(ll2, DistanceUnits.MILES); }
/// <summary> /// Calculate the midpoint between this point an another. Respects fixed vs floating point /// </summary> /// <param name="other">The other.</param> /// <returns></returns> public abstract LatLng CalculateMidpoint(LatLng other);
public override LatLng CalculateMidpoint(LatLng other) { return(new FixedLatLng((_lat + other.GetFixedLat()) / 2, (_lng + other.GetFixedLng()) / 2)); }