跳到主要内容

行政区划查询

行政区划查询​

按 country/province/city/district 层级查询,可传 query 及已发现的父级 countryCode/provinceCode/cityCode。limit 为 1–100,默认 20。检查 total、truncated、scopeIssue、coverage,不要自动采用有歧义的第一项。这是行政区划查询,不验证坐标或详细街道地址,修正区划时保留原地址文本。

system.location.region.search​

sl system location region search (--definition-json <json>|--definition-file <path>) [--json]

参数(? 表示可选;定义 JSON 使用 Runtime 字段名):

level, query?, countryCode?, provinceCode?, cityCode?, limit?。

sl system location region search --definition-json '{"level":"country","query":"China","limit":10}' --json

测距与路线计算​

system.location.distance.calculate​

sl system location distance calculate --definition-json '{"origin":{"longitude":116.35506,"latitude":39.92277},"destination":{"longitude":116.39751,"latitude":39.90854}}' --json

使用 WGS84 坐标本地计算球面直线距离,返回 distanceMeters 和 coordinateSystem: "WGS84",无需地图资源。

system.location.route.calculate​

sl system location route calculate --definition-json '{"resourceKey":"tianditu-map-main","origin":{"longitude":116.35506,"latitude":39.92277},"destination":{"longitude":116.39751,"latitude":39.90854},"mode":"driving"}' --json

resourceKey 必须指向当前租户已启用的地图资源;也可以改填 provider(tianditu、mapbox、google)和 apiKey,两种方式不可混用。origin、destination 必须为 WGS84 { longitude, latitude }。mode 默认 driving,三家支持 walking,Mapbox/Google 另支持 cycling。返回 { resourceKey, provider, mode, coordinateSystem, distanceMeters, durationSeconds, path, alternatives },path 为 [经度, 纬度][]。资源方式使用当前的 apiKey;直接传入 Key 时不读取或保存地图资源,返回 resourceKey: null。实际凭据须允许路线 API 和服务端访问,并具备配额及所需计费。错误直接返回,不切换供应商或用直线代替路线。两条命令均支持 --definition-file 替代 --definition-json。

自行填写 Key 时,将以下内容保存到文件,运行 sl system location route calculate --definition-file route.json --json:

{"provider":"mapbox","apiKey":"YOUR_SERVER_ROUTE_KEY","origin":{"longitude":116.35506,"latitude":39.92277},"destination":{"longitude":116.39751,"latitude":39.90854},"mode":"driving"}

备选路线​

资源模式和直接填写 Key 均支持设置 alternatives: true,请求 Mapbox 或 Google 的备选路线。顶层 distanceMeters、durationSeconds、path 为首选路线,返回的 alternatives 只包含额外路线,每项都有相同的三个字段。默认 false 返回 alternatives: []。Mapbox 最多两条备选,Google 最多三条,也可能没有备选;当前天地图接入传 true 会抛出 MAP_ROUTE_ALTERNATIVES_UNSUPPORTED,不会向服务商发送请求。

sl system location route calculate --definition-json '{"resourceKey":"mapbox-main","origin":{"longitude":116.35506,"latitude":39.92277},"destination":{"longitude":116.39751,"latitude":39.90854},"mode":"driving","alternatives":true}' --json