# 4.1 设施查询(Place Searching)
设施搜索服务,提供某一特定地区的设施查询服务。PlaceSearch构造函数的参数为可选,表达为参数对象PlaceSearchOptions。PlaceSearchOptions允许设置搜索城市、搜索数据类别等。用户可以通过自定义回调函数取回并显示查询结果。若服务请求失败,系统将返回错误信息。
# 构造函数
// 创建设施查询类的实例
const searching = new aimap.PlaceSearch({
city: "上海市",
pageSize: 20
});
2
3
4
5
# PlaceSearchOptions 字段说明
| PlaceSearchOptions | 类型 | 说明 |
|---|---|---|
| city | String | 兴趣点城市可选值:城市名中文 |
| categories | Array<String> | 兴趣点类别 |
| pageSize | Number | 单页显示结果条数默认值:10取值范围:1-50,超出取值范围按最大值返回 |
| pageToken | String | 页码。(如pageToken为2,pageSize为10,那么显示的应是第11-20条返回结果)默认值:1取值范围:1-100,超过实际页数不返回poi |
# 成员函数
search(keyword:String, callback: (status: String, result: SearchResult)),根据关键字搜索
根据关键字搜索,关键字支持中文。当error为null或者undefined时,result为SearchResult;当error有值时,表示出现错误,result为undefined。
# 示例
const searching = new aimap.PlaceSearch();
searching.search("老港镇", (error, result) => {
console.log(result);
});
2
3
4
nearby(keyword: String, center: LngLat, radius: Number, callback: (status: String, result: SearchResult)),根据半径进行周边查询
根据中心点经纬度、半径以及关键字进行周边查询。radius取值范围:0-50000。status说明同上。
# 示例
const searching = new aimap.PlaceSearch();
searching.nearby("小区", new aimap.LngLat(121.58697,31.201464), 1000, (error, result) => {
console.log(result);
});
2
3
4
# 返回对象说明
# SearchResult
| 属性 | 类型 | 说明 |
|---|---|---|
| places | Array<Place> | Place列表 |
| pageToken | Number | 页码 |
| pageSize | String | 单页结果数 |
| total | Number | 查询结果总数 |
# Place
| 属性 | 类型 | 说明 |
|---|---|---|
| id | string | 设施ID |
| name | string | 设施名称 |
| center | aimap.LngLat | 设施中心点 |
# 4.2 地理编码与逆地理编码(Geocoder)
aimap.Geocoder地理编码与逆地理编码类,用于地址描述与坐标之间的转换。用户可以通过自定义回调函数取回并显示查询结果 (opens new window)。若服务请求失败,系统将返回错误信息 (opens new window)。
# 构造函数
// 提供地理编码或逆地理编码功能
const geocoder = new aimap.Geocoder({
city: "上海市"
});
2
3
4
# GeocoderOptions字段说明
| GeocoderOptions | 类型 | 说明 |
|---|---|---|
city | String | 城市,地理编码时,设置地址描述所在城市可选值:城市名(中文或中文全拼)、citycode、adcode;默认值:“全国” |
radius | Number | 逆地理编码时,以给定坐标为中心点,单位:米取值范围:0-3000默认值:1000 |
spatialReference | String | 逆地理编码时,输入中心点坐标的坐标系,支持gcj02,wgs84,cgcs2000 |
# 成员函数
getLocation(address: String, callback:(error: String, location: Geocode)),地址转坐标
根据给定的地址描述进行解析,支持中文。当error为null或者undefined时,location为Geocode;当error有值时,表示出现错误,location为undefined。
# 示例
const geocoder = new aimap.Geocoder();
geocoder.getLocation("陆家嘴街道福沈居委张杨路951弄1号", (error, result) => {
// 获取街镇
console.log(`the township is: ${result.address.context.township}`)
// 获取村居
console.log(`the township is: ${result.address.context.neighborhood}`)
});
2
3
4
5
6
7
8
getAddress(location: LngLat,callback:(error: String, address: Regeocode)),坐标转地址
根据给定坐标进行解析,当error为null或者undefined时,address为Regeocode;当error有值时,表示出现错误,location为undefined。
# 示例
const geocoder = new aimap.Geocoder();
geocoder.getAddress(new aimap.LngLat(121.58697, 31.201464), (error, result) => {
console.log(result);
// 获取街镇
console.log(`the township is: ${result.address.context.township}`)
// 获取村居
console.log(`the township is: ${result.address.context.neighborhood}`)
});
2
3
4
5
6
7
8
9
# 返回对象说明
# Geocode
| 属性 | 类型 | 说明 |
|---|---|---|
| address | Address | 详细地址对象 |
| position | Position | 坐标 |
# Regeocode
| 属性 | 类型 | 说明 |
|---|---|---|
| address | Address | 详细地址对象 |
| place | Place | 指定坐标点对应的设施Place |
# Address
| 属性 | 类型 | 说明 |
|---|---|---|
| name | String | 格式化地址 规则:地址信息=基本行政区信息+具体信息; |
| context | AddressContext | 地址组成元素 |
| level | Number | 给定地址匹配级别,返回匹配最详细级别 |
# AddressContext
| 属性 | 类型 | 说明 |
|---|---|---|
| country | ContextArea | 所在国家 |
| province | ContextArea | 所在省 |
| city | ContextArea | 所在城市 |
| district | ContextArea | 所在区县 |
| township | ContextArea | 所在街镇 |
| neighborhood | ContextArea | 所在村居 |
| boundingArea | ContextArea | 所在小区 |
| building | ContextArea | 所在建筑 |
# ContextArea
| 属性 | 类型 | 说明 |
|---|---|---|
| id | ContextArea | 区域ID |
| name | ContextArea | 区域编码名称 |
| code | ContextArea | 区域编码 |
# Position
| 属性 | 类型 | 说明 |
|---|---|---|
| point | aimap.LngLat | 地址所在的坐标 |
| spatialReference | string | 坐标投影系,默认为:gcj02 |
| accuracy | float | 坐标点的精度 |
# Place
| 属性 | 类型 | 说明 |
|---|---|---|
| id | string | 设施ID |
| name | string | 设施名称 |
| coordinates | aimap.LngLat | 设施默认的坐标点 |
| center | aimap.LngLat | 设施中心点 |
# 4.3 路径演算(Routing)
路径演算提供的步行、公交、驾车查询及行驶距离计算接口,用于实现路径规划功能的开发。由于道路/数据/算法的变更,很可能存在间隔一段时间后请求相同起终点的经纬度返回不同结果。
# 构造函数
const routingOptions = {
origin: [121.603886, 31.179786],
destination: [121.634876, 31.183456],
};
const routing = new aimap.Routing(routingOptions);
2
3
4
5
# RoutingOptions字段说明
| RoutingOptions | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| origin | Array<Number> | 是 | lng,lat(经度,纬度),如117.500244, 40.417801 经纬度小数点不超过6位 |
| destination | Array<Number> | 是 | lng,lat(经度,纬度),如117.500244, 40.417801 经纬度小数点不超过6位 |
| strategy | string | 否 | 路径演算策略,参见下方strategy的说明,默认speed |
| waypoints | Array<[Number, Number]> | 否 | 途经点,最大数目:16个坐标点,经纬度小数点不超过6位 |
| avoidPolygon | Array<[Number, Number]> | 否 | 只支持一个避让区域,如果是四边形则有四个坐标点,如果是五边形则有五个坐标点 |
| avoidRoad | string | 否 | 只支持一条避让道路,如:南京西路 |
| mode | string | 否 | 默认:driving,当前只⽀持driving模式 |
# strategy(策略)
| 名称 | 说明 |
|---|---|
| speed | 速度优先 |
| cost | 费用优先,不走收费路段,且耗时最少的路线 |
| distance | 距离优先,不考虑路况,仅走距离最短的路线,但是可能存在穿越小路/小区的情况 |
| highway | 高速优先 |
| avoidHighway | 不走高速 |
# 成员函数
route(callback:(error: String, result: RoutingResult)),发起查询
用于出行查询及行驶距离计算。
# 示例
const routing = new aimap.Routing({
origin: [121.603886, 31.179786],
destination: [121.634876, 31.183456],
});
routing.route((error, result) => {
console.log(result);
});
2
3
4
5
6
7
8
# 返回对象说明
# RoutingResult
| 参数 | 类型 | 说明 |
|---|---|---|
| []Route | 路径 |
# Route
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| summary | Summary | 是 | 概要 |
| locations | []Location | 是 | 路径演算起点和终点 |
| legs | []Leg | 是 | 路径 |
# Summary
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| boundingBox | BoundingBox | bounding | |
| duration | int32 | 耗时,单位为秒 | |
| length | float | 长度,单位为公里 |
# BoundingBox
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| leftBottom | LngLat | 左下角 | |
| rightTop | LngLat | 右上角 |
# LngLat
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| longitude | double | 经度 | |
| latitude | double | 纬度 |
# Location
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| originalIndex | int32 | 是 | 序列号,用于说明location的顺序 |
| longitude | double | 是 | 经度 |
| latitude | double | 是 | 纬度 |
| sideOfStreet | string | 否 | left,right |
# Leg
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| summary | Summary | 是 | 概要 |
| steps | []Step | 是 | 导航路段 |
# Step
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| instruction | string | 是 | 指示 |
| roadName | string | 否 | 所在道路名称 |
| duration | int32 | 是 | 耗时 |
| length | float | 是 | 长度,单位为公里 |
| toll | bool | 否 | 是否存在收费 |
| action | string | 是 | 导航主要动作 |
| assistantAction | string | 否 | 导航辅助动作 |
| geometry | Geometry | 是 | 此路段坐标点串 |
# Action
| type | 数值 | 中文值 |
|---|---|---|
| none | 0 | 无基本导航动作 |
| left | 1 | 左转 |
| right | 2 | 右转 |
| left-head | 11 | 向左前方行驶 |
| right-head | 12 | 向右前方行驶 |
| left-back | 21 | 向左后方行驶 |
| right-back | 22 | 向右后方行驶 |
| left-uturn | 3 | 左转调头 |
| head | 4 | 直行 |
| keep-left | 31 | 靠左 |
| keep-right | 32 | 靠右 |
| enter-roundabout | 6 | 进入环岛 |
| exit-roundabout | 7 | 离开环岛 |
| slowdown | 9 | 减速行驶 |
# Assistant Action
| type | 值 | 字符串值 |
|---|---|---|
| 0 | 无辅助导航动作 | |
| 101 | 进入主路 | |
| 102 | 进入辅路 | |
| 103 | 进入高速 | |
| 104 | 进入匝道 | |
| 105 | 进入隧道 | |
| 106 | 进入左岔路 | |
| 107 | 进入中间岔道 | |
| 108 | 进入右岔路 | |
| 109 | 进入右转专用道 | |
| 110 | 进入左转专用道 | |
| 111 | 进入左侧道路 | |
| 112 | 进入中间道路 | |
| 113 | 进入右侧道路 |
# Geometry
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| type | string | LineString | |
| coordinates | array<array<double>> | 坐标 |
# 4.4 路径查询(EdgesSearch)
用于查询道路的详细信息。
# 构造函数
const edgeSearchOptions = {
points: [[121.603886, 31.179786, -1, 20]],
};
const edgeSearch = new aimap.EdgesSearch(edgeSearchOptions);
2
3
4
5
# EdgeSearchOptions字段说明
| EdgeSearchOptions | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| points | Array<Point> | 是 | lng,lat,direction,speed(经度,纬度,⽅向,速度) |
# Point
Point由一个长度为4的数组组成,依次为 lng,lat,direction,speed。
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| lng | Number | 是 | 经度 |
| lat | Number | 是 | 纬度 |
| direction | Number | 是 | 正北顺时针⽅向,取值范围[0,360),-1为⽅向不确定 |
| speed | Number | 是 | ⽶/秒 |
# 成员函数
search(callback:(error: String, result: EdgeSearchResult)),发起查询
用于查询路径的详细信息。
# 示例
const edgeSearch = new aimap.EdgesSearch({
points: [[121.603886, 31.179786, -1, 20]],
});
edgeSearch.search((error, result) => {
console.log(result);
});
2
3
4
5
6
7
# 返回对象说明
# EdgeSearchResult
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| kind | int | 是 | 道路类型 |
| speed | Speed | 是 | 道路限速信息 |
| name | string | 是 | 道路名称 |
| tolled | bool | 否 | 是否收费 |
# Speed
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| limit | int32 | 是 | 一般限速 |
| truckLimit | int32 | 否 | 卡车限速 |
| limitFromGrade | bool | 否 | 是否通过道路等级获取的限速 |
# kind列表说明
| 值 | 说明 |
|---|---|
| 1 | ⾼速道路 |
| 2 | 城市⾼速道路 |
| 3 | 国道 |
| 4 | 省道 |
| 6 | 快速道路 |
| 7 | 主⼲道路 |
| 8 | 次要道路 |
| 9 | ⼀般道路 |
| 10 | 窄道路 |
| 11 | 其他道路 |
| 12 | 规划道路 |
| 14 | ⼩区道路 |
| 100 | 轮渡 |
# 4.5 可达圈(Isochrone)
用于计算从某一点出发,在指定时间范围内,可到达的区域范围。
# 构造函数
const isochroneOptions = {
location: [121.604801, 31.179503],
costing: 'pedestrian',
contourTime: 15,
polygon: true,
denoise: 1,
};
const isochrone = new aimap.Isochrone(isochroneOptions);
2
3
4
5
6
7
8
# IsochroneOptions字段说明
| IsochroneOptions | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| location | Array<Number> | 是 | lng,lat(经度,纬度),如121.604801,31.179503,经纬度小数点不超过6位 |
| costing | string | 是 | 参见下方costing的说明 |
| contour_time | Number | 是 | 分钟数,比如15、30、60,取值范围为[0,120] |
| polygon | Boolean | 否 | 是否返回为polygon,默认值为false |
| denoise | Number | 否 | 去除噪声,取值范围为[0.0,1.0],值越大,噪声去除效果越明显,默认值为0.0 |
# costing
| 取值 | 说明 |
|---|---|
| pedestrian | 步行 |
| bicycle | 骑行 |
| driving | 驾行 |
# 成员函数
query(callback:(error: String, result: RoutingResult)),发起查询
用于查询在给定参数下的可到达的范围。
# 示例
const isochrone = new aimap.Isochrone({
location: [121.604801, 31.179503],
costing: 'pedestrian',
contourTime,
polygon: true,
denoise: 1,
});
isochrone.query((error, result) => {
console.log(result);
});
2
3
4
5
6
7
8
9
10
11
# 返回对象说明
| 参数 | 类型 | 是否必有值 | 说明 |
|---|---|---|---|
| GeoJson | 是 | 到达圈 |