1 高德地图Web服务
1.1 添加Key
注册高德地图,进入控制台,创建新应用,添加Key,选择Web服务,不添加域名白名单,勾选同意政策。
刷新界面,记住获取到的Key。
1.2 下载安装Postman
https://www.postman.com/downloads/
1.3 使用Web服务API
学习链接:
1.3.1 地理编码
发送位置信息,获取经纬度信息。
打开Postman,网址输入:https://restapi.amap.com/v3/geocode/geo
请求方式选择:GET
按照高德地图官方文档:
在Postman中设置Params参数:
发送请求后可以得到如下反馈:
{"status":"1","info":"OK","infocode":"10000","count":"2","geocodes":[{"formatted_address":"北京市朝阳区阜通东大街6号","country":"中国","province":"北京市","citycode":"010","city":"北京市","district":"朝阳区","township":[],"neighborhood":{"name":[],"type":[]},"building":{"name":[],"type":[]},"adcode":"110105","street":"阜通东大街","number":"6号","location":"116.482086,39.990496","level":"门址"},{"formatted_address":"北京市朝阳区阜通东大街6号院","country":"中国","province":"北京市","citycode":"010","city":"北京市","district":"朝阳区","township":[],"neighborhood":{"name":[],"type":[]},"building":{"name":[],"type":[]},"adcode":"110105","street":"阜通东大街","number":"6号院","location":"116.482145,39.990039","level":"门址"}]}
可以发现已经得到该位置的经纬度信息location。
1.3.2 逆地理编码
发送经纬度信息,获取位置信息。
请求网址:https://restapi.amap.com/v3/geocode/regeo
请求方式:GET
请求参数:
Postman界面设置:
发送请求后,得到如下数据:
{"status":"1","regeocode":{"addressComponent":{"city":"湖州市","province":"浙江省","adcode":"330522","district":"长兴县","towncode":"330522101000","streetNumber":{"number":[],"direction":[],"distance":[],"street":[]},"country":"中国","township":"洪桥镇","businessAreas":[[]],"building":{"name":[],"type":[]},"neighborhood":{"name":[],"type":[]},"citycode":"0572"},"formatted_address":"浙江省湖州市长兴县洪桥镇南庄湾"},"info":"OK","infocode":"10000"}
1.4 使用猎鹰轨迹服务
官方链接:
本小节讲解创建围栏,并判断终端是否在围栏内部。
1.4.1 创建服务
首先创建猎鹰轨迹服务。
服务地址:https://tsapi.amap.com/v1/track/service/add
请求方式:POST
请求参数:
Postman设置:输入网址,选择POST请求,选择Body,选择x-www-form-urlencoded方式传输,添加key参数和name参数。
返回结果:
{
"errcode": 10000,
"errmsg": "OK",
"data": {
"name": "gps_fence",
"sid": 10*****
}
}
1.4.2 创建终端
服务地址:https://tsapi.amap.com/v1/track/terminal/add
请求方式:POST
请求参数:
Postman设置:
返回数据:
{
"errcode": 10000,
"errmsg": "OK",
"data": {
"name": "devicetest",
"tid": 820******,
"sid": 10*****
}
}
1.4.3 创建轨迹
服务地址:https://tsapi.amap.com/v1/track/trace/add
请求方式:POST
请求参数:
Postman设置:
返回数据:
{
"errcode": 10000,
"errmsg": "OK",
"data": {
"trid": 20
}
}
1.4.3 终端坐标位置上传
服务地址:https://tsapi.amap.com/v1/track/point/upload
请求方式:POST
请求参数:
postman设置:
返回数据:
{
"errcode": 20100,
"errmsg": "OK",
"errdetail": "PARTIAL_SUCCESS",
"data": {
"errorpoints": [
{
"_param_err_info": "locatetime",
"_err_point_index": 0,
"location": "120.001,31.001",
"locatetime": 1704616525
}
]
}
}
1.4.4 创建围栏
这里创建圆形围栏。
服务地址:https://tsapi.amap.com/v1/track/geofence/add/circle
请求方式:POST
请求参数:
Postman设置:
返回数据:
{
"errcode": 10000,
"errmsg": "OK",
"data": {
"gfid": 11*****
}
}
1.4.5 添加围栏对象
将一个或多个终端添加到围栏内。
服务地址:https://tsapi.amap.com/v1/track/geofence/terminal/bind
请求方式:POST
请求参数:
Postman设置:
接收数据:
{
"errcode": 10000,
"errmsg": "OK",
"data": {
"tids": [
820*******
]
}
}
1.4.6 围栏关系判断
输入检测对象或者指定坐标,判断与围栏的关系,返回"in"为1,表示在围栏内;返回"in"为0,表示在围栏外。
在上方已经设置了圆形围栏中心点[120,31],半径500米,终端轨迹坐标[120.001,31.001]。
服务地址:https://tsapi.amap.com/v1/track/geofence/status/terminal
请求方式:GET
请求参数:
postman设置:
这里与之前不同,设置GET和Params,Body要设置为none。
返回数据:
{
"errcode": 10000,
"errmsg": "OK",
"data": {
"count": 1,
"results": [
{
"gfid": 1163031,
"gfname": "fence-01",
"in": 0
}
]
}
}
可以发现in为0,说明终端不在围栏里。