NEST 中的距离单位
Distance units
Version: 5.x
英文原文地址:Distance units
当我们需要指定距离时(地理位置查询),可以使用一个双精度的数字来表示,它的默认单位是米(meters)。除此之外,也可以使用一个包含数字和单位的字符串(如:"2.72km" )。
NEST 使用 Distance 类型来规范距离,并提供了几种方式来构造这种类型的对象。
Constructor
最直接的方式是使用构造函数来构造 Distance 对象
var unitComposed = new Distance(25);
var unitComposedWithUnits = new Distance(25, Nest.DistanceUnit.Meters);
Distance 对象会被序列化为一个由因子和距离单位构成的字符串。因子是一个双精度的数字,所以序列化时至少保留一位小数
Expect("25.0m")
.WhenSerializing(unitComposed)
.WhenSerializing(unitComposedWithUnits);
Implicit conversion
或者,将一个表示距离的 string 直接赋值给 Distance 变量,内部会执行一次隐式转换,从而构造一个 Distance 实例。如果没有指定 DistanceUnit ,默认单位是米
Distance distanceString = "25";
Distance distanceStringWithUnits = "25m";
Expect(new Distance(25))
.WhenSerializing(distanceString)
.WhenSerializing(distanceStringWithUnits);
Supported units
NEST 支持数个距离单位,从毫米到海里
Metric
mm (Millimeters) 毫米
Expect("2.0mm").WhenSerializing(new Distance(2, Nest.DistanceUnit.Millimeters));
cm (Centimeters) 厘米
Expect("123.456cm").WhenSerializing(new Distance(123.456, Nest.DistanceUnit.Centimeters));
m (Meters) 米
Expect("400.0m").WhenSerializing(new Distance(400, Nest.DistanceUnit.Meters));
km (Kilometers) 千米
Expect("0.1km").WhenSerializing(new Distance(0.1, Nest.DistanceUnit.Kilometers));
Imperial
in (Inches) 英寸
Expect("43.23in").WhenSerializing(new Distance(43.23, Nest.DistanceUnit.Inch));
ft (Feet) 英尺
Expect("3.33ft").WhenSerializing(new Distance(3.33, Nest.DistanceUnit.Feet));
yd (Yards) 码
Expect("9.0yd").WhenSerializing(new Distance(9, Nest.DistanceUnit.Yards));
mi (Miles) 英里
Expect("0.62mi").WhenSerializing(new Distance(0.62, Nest.DistanceUnit.Miles));
nmi or NM (Nautical Miles) 海里
Expect("45.5nmi").WhenSerializing(new Distance(45.5, Nest.DistanceUnit.NauticalMiles));
1 英寸 = 2.54 厘米
1 英尺 = 12 英寸
1 码 = 3 英尺
1 英里 = 1760 码
1 海里 = 1852 米
NEST 中的距离单位的更多相关文章
- NEST 中的时间单位
Time units 英文原文地址:Time units 与 Elasticsearch 交互,我们会遇到需要设定时间段的情况(例如:timeout 参数).为了指定时间段,我们可以使用一个表示时间的 ...
- Android中的距离单位
px 像素:每个px对应屏幕上面的一个点 dip或dp(device independent pixels 设备独立像素):一种基于屏幕密度的抽象单位.在每英寸160点的显示器上,1dip=1px.但 ...
- [转] MachingLearning中的距离相似性计算以及python实现
参考:https://blog.csdn.net/gamer_gyt/article/details/75165842#t16 https://blog.csdn.net/ymlgrss/artic ...
- 移动端rem距离单位的使用
在做移动端开发的时候大家肯定会遇到适配问题,手机的屏幕大小有非常多的类别,使用传统的px距离单位已经无法满足我们的需要,于是rem便横空出世,他与百分比定位是比较像的,但是也是有一定的区别,在这里就跟 ...
- .net中判断距离高考多长时间的js函数
在JS中判断距离高考(此处举例高考)的时间函数 JS中代码: function djs() { var severtime= new Date(); //获取服务器日期 var year=severt ...
- Leetcode 863. 二叉树中所有距离为 K 的结点
863. 二叉树中所有距离为 K 的结点 显示英文描述 我的提交返回竞赛 用户通过次数39 用户尝试次数59 通过次数39 提交次数174 题目难度Medium 给定一个二叉树(具有根结点 ro ...
- 【前缀思想】二叉树中所有距离为 K 的结点
863. 二叉树中所有距离为 K 的结点 class Solution { Map<TreeNode,String>map=new HashMap<>(); String pa ...
- Leetcode——863.二叉树中所有距离为 K 的结点
给定一个二叉树(具有根结点 root), 一个目标结点 target ,和一个整数值 K . 返回到目标结点 target 距离为 K 的所有结点的值的列表. 答案可以以任何顺序返回. 示例 1: 输 ...
- CSS3中的rem单位
一.rem介绍 rem是什么? 它的全称是 font size of the root element (根元素的字体大小) 它是CSS3中新增加的一个尺寸(度量)单位,根节点(html)的font- ...
随机推荐
- C++著名程序库的比较和学习经验
内容目录:1.C++各大有名库的介绍——C++标准库2.C++各大有名库的介绍——准标准库Boost3.C++各大有名库的介绍——GUI4.C++各大有名库的介绍——网络通信5.C++各大有名库的介绍 ...
- 钉钉消息通知机器人python版
参考官方文档https://open-doc.dingtalk.com/microapp/serverapi2/qf2nxq #coding=utf8 import requests import j ...
- hibernate框架学习之数据查询(HQL)helloworld
package cn.itcast.h3.hql; import java.util.List; import org.hibernate.Query; import org.hibernate.Se ...
- Xamarin AVD x86 问题
inspired by https://stackoverflow.com/questions/34282243/error-while-starting-emulator/34282302#3428 ...
- [PHP]session的一些要点
一.session_start([array $options=array()]) 1.只能在输出http头前启动此函数,因为如果需要改写sessid的键和值,需要在http报文头发出前就开始定义了: ...
- [Linux]php+apache 和 php+nginx的区别
apache是通过mod_php来解析php nginx是通过php-fpm(fast-cgi)来解析php1. PHP 解释器是否嵌入 Web 服务器进程内部执行mod_php 通过嵌入 PHP 解 ...
- ICO和IPO
ICO 和 IPOIPO:在经过种子轮,天使轮,x轮之后已经非常成熟的状态下进行的投资,基本上是盈利的,上市的是股份,现金流ICO:早期有一个idea,然后又很多的小散户进行的几千万-几亿的投资,风险 ...
- npm i 和 npm install 的区别
实际使用的区别点主要如下(windows下): 1. 用npm i安装的模块无法用npm uninstall删除,用npm uninstall i才卸载掉 2. npm i会帮助检测与当前node版本 ...
- Golang的优雅重启
更新(2015年4月):Florian von Bock已将本文中描述的内容转换为一个名为endless的优秀Go包 . 如果您有Golang HTTP服务,可能需要重新启动它以升级二进制文件或更改某 ...
- 手机CPU架构体系分类及各大厂商
手机cpu相关知识,这对于开发Android应用程序适应各个机型有一定的辅助作用 . 手机cpu架构体系分类 指令集可分为复杂指令集(CISC)和精简指令集(RISC)两部分,代表架构分别是x86.A ...