WARNING: Version 5.x has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Whenever distances need to be specified, e.g. for a geo distance query,
the distance unit can be specified as a double number representing distance in meters, as a new instance of
Distance, or as a string of the form number and distance unit e.g. "
NEST uses a
Distance type to strongly type distance units and there are several ways to construct one.
The most straight forward way to construct a
Distance is through its constructor
var unitComposed = new Distance(25); var unitComposedWithUnits = new Distance(25, Nest.DistanceUnit.Meters);
Distance serializes to a string composed of a factor and distance unit.
The factor is a double so always has at least one decimal place when serialized
Expect("25.0m") .WhenSerializing(unitComposed) .WhenSerializing(unitComposedWithUnits);
Alternatively a distance unit
string can be assigned to a
Distance, resulting in an implicit conversion to a new
DistanceUnit is specified, the default distance unit is meters
Distance distanceString = "25"; Distance distanceStringWithUnits = "25m"; Expect(new Distance(25)) .WhenSerializing(distanceString) .WhenSerializing(distanceStringWithUnits);
A number of distance units are supported, from millimeters to nautical miles
Expect("2.0mm").WhenSerializing(new Distance(2, Nest.DistanceUnit.Millimeters));
Expect("123.456cm").WhenSerializing(new Distance(123.456, Nest.DistanceUnit.Centimeters));
Expect("400.0m").WhenSerializing(new Distance(400, Nest.DistanceUnit.Meters));
Expect("0.1km").WhenSerializing(new Distance(0.1, Nest.DistanceUnit.Kilometers));
Expect("43.23in").WhenSerializing(new Distance(43.23, Nest.DistanceUnit.Inch));
Expect("3.33ft").WhenSerializing(new Distance(3.33, Nest.DistanceUnit.Feet));
Expect("9.0yd").WhenSerializing(new Distance(9, Nest.DistanceUnit.Yards));
Expect("0.62mi").WhenSerializing(new Distance(0.62, Nest.DistanceUnit.Miles));
NM (Nautical Miles)
Expect("45.5nmi").WhenSerializing(new Distance(45.5, Nest.DistanceUnit.NauticalMiles));