/// <summary> /// Returns <see langword="true"/> if current instance is equivalent to <see cref="other"/>, else <see langword="false"/> /// </summary> /// <param name="other"></param> /// <returns></returns> public bool Equals(Position other) { if (ReferenceEquals(null, other)) { return false; } if (ReferenceEquals(this, other)) { return true; } return Equals(other.Longitude, Longitude) && Equals(other.Latitude, Latitude); }
/// <summary> /// Returns the distance between this position and <see cref="position"/> in meters /// </summary> /// <param name="position"></param> /// <returns></returns> public double DistanceFrom(Position position) { double lat1 = Latitude.RawValue.ToRadians(); double long1 = Longitude.RawValue.ToRadians(); double lat2 = position.Latitude.RawValue.ToRadians(); double long2 = position.Longitude.RawValue.ToRadians(); double longitudeDistance = long1 - long2; double latitudeDistance = lat1 - lat2; double a = Math.Pow(Math.Sin(latitudeDistance / 2.0), 2.0) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Pow(Math.Sin(longitudeDistance / 2.0), 2.0); double c = 2.0*Math.Atan2(Math.Sqrt(a), Math.Sqrt(1.0 - a)); const double radiusOfEarth = 6371009; return radiusOfEarth*c; }