public Coordinate(LatLonCoordinate coords) { var xDist = GetLonDistance(coords); var yDist = Distance.Measure(coords, new LatLonCoordinate(-90f, coords.Long)); X = (long)xDist.InMeters; Y = (long)yDist.InMeters; FractionX = (float)(xDist.InMeters % 1); FractionY = (float)(yDist.InMeters % 1); }
private static Distance GetLonDistance(LatLonCoordinate coords) { if (coords.Long < 180f) { return(Distance.Measure(coords, new LatLonCoordinate(coords.Lat, 0.0))); } else { return(Distance.Measure(coords, new LatLonCoordinate(coords.Lat, 180)) + Distance.Measure(new LatLonCoordinate(coords.Lat, 180), new LatLonCoordinate(coords.Lat, 0))); } }
public static Distance Measure(LatLonCoordinate p0, LatLonCoordinate p1) { var deltaLat = ToRad(p1.Lat - p0.Lat); var deltaLong = ToRad(p1.Long - p0.Long); var a = Math.Pow(Math.Sin(deltaLat / 2), 2) + Math.Cos(ToRad(p0.Lat)) * Math.Cos(ToRad(p1.Lat)) * Math.Pow(Math.Sin(deltaLong / 2), 2); var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); return(Distance.FromKm(EarthRadius * c)); }