可以通过蓝牙、WI-FI、基站、卫星等获取用户位置数据。
利用蓝牙、WI-FI、基站、卫星等信息,传给服务端进行处理,获取定位信息,完成地图、路线规划、轨迹等功能。
适用于室内、室外多种定位场景,覆盖智能可穿戴设备、车载设备等。(目前该服务只针对百度深度合作用户开放)
如果您的应用为Android Native App,建议使用Android定位SDK,定位效果最佳,精度可达到10m,且无任何使用配额及并发量的限制。
可判断当前定位点在室内或者室外,支持室内场景下返回建筑物名称、当前楼层信息。目前百度地图覆盖全国4000多家商场、机场、火车站等室内场所。
https://api.map.baidu.com/locapi/v2 // POST请求
请求头
参数名称 | 参数含义 | 类型 | 备注 |
---|---|---|---|
key |
用户唯一标识,用户可在API控制台申请,应用类型建议选择服务端 |
string | 必选 |
|
定位请求来源,厂商标 识,比如(baidu),开发者可自定义 |
string | |
|
产品线名称,比如(baiduwatch),开发者可自定义 |
string | |
|
申请服务版本号,目前只提供1.0服务 |
string | |
trace |
是否开启trace,若为true,则将定位记录 到鹰眼(暂不开通) |
bool |
|
请求体:
参数名称 | 参数含义 | 类型 | 备注 |
---|---|---|---|
accesstype |
移动端接入网络方式 可选值: 移动接入网络:0 wifi接入网络:1 仅gps坐标转换:2 默认值:无 |
int | 必选 |
|
手机mac码 默认值:无 此参数能够提高定位精度和准确度,且定位不到时可依据此参数进行跟踪排查,如没有则无法排查和跟踪问题。 |
string | |
|
移动网关IP 默认值:无 此参数能够提高定位精度和准确度,且定位不到时可依据此参数进行跟踪排查,如没有则无法排查和跟踪问题。 |
string | |
cdma |
是否为cdma。 非cdma:0; cdma:1 默认值为:0 |
int |
|
imsi |
移动用户识别码 默认值:无 此参数能够提高定位精度和准确度,且定位不到时可依据此参数进行跟踪排查,如没有则无法排查和跟踪问题。 |
string |
|
gps |
手机GPS数据 取值规则: 经度|纬度|半径 |
string |
|
network |
无线网络类型 GSM/GPRS/EDGE/HSUPA/HSDPA/WCDMA (注意大写) |
string |
|
tel |
手机号码 |
string |
|
bts |
基站信息,非CDMA格式为:mcc, mnc,lac,cellid,signal;其中lac,cellid必须填写,signal如无法获取请填写50,前两位mcc, mnc 如无法获取,请填写-1 |
string |
|
nearbts |
周边基站信息 基站信息1|基站信息2|基站信息3…. |
string |
|
mmac |
已连热点mac信息 mac,signal,ssid。 如:f0:7d:68:9e:7d:18,-41,TPLink 非必选,但强烈建议填写 |
string |
|
macs |
WI-FI列表中mac信息 单mac信息同mmac,mac之间使用“|”分隔。 必须填写 2 个及 2 个以上,30 个 以内的方可正常定位。 请不要包含移动WI-FI信息 |
string |
|
coor |
可指定坐标系(GCJ02|BD09LL),注意大写。 |
string |
|
output |
返回数据格式类型(注意大写) 可选值:JSON, XML 默认值:JSON 一期只支持JSON |
string |
|
ctime |
客户端时间戳 |
string |
|
need_rgc |
返回地址信息,默认不返回 Y : 返回rgc结果 N : 不返回rgc结果 |
string |
|
特别说明: 为了尽可能地保证您定位结果的精确性以及问题追踪,除了必须填写的参数外,其他可以获得的参数尽可能的传入。 例如:WI-FI接入网络的情况下,也可以传入其对应的基站信息;而在移动接入网络的情况下,也可传入 WI-FI列表中 mac 信息(macs)。
返回结果(JSON格式):
结果字段 | 字段含义 | 类型 |
type |
定位类型,0:没有得到定位结果;1:gps 定位结果;2:wifi定位结果;3:混合定位 结果;4:基站定位结果;5:其他-- |
int |
location |
定位经纬度(经度,纬度) |
string |
radius |
定位精度半径,单位:米 |
int |
desc |
位置描述 |
string |
country |
国家 | string |
province |
省 | string |
city |
市 | string |
citycode |
城市编码 |
string |
district |
县区 |
string |
road |
道路名 |
string |
ctime |
客户端请求时间戳,批量请求时用于匹配 服务端响应和客户端请求 |
string |
bldg |
建筑物简称 |
string |
bldgid | 建筑物ID | string |
bldgname |
建筑物 |
string |
floor |
楼层 |
string |
indoor |
是否室内:0:室外 1:室内 |
string |
error |
定位是否成功 0: 成功 -1:失败 |
int |
完整请求可包含多条请求数据,示例如下:
{ "ver": "1.0", "trace": false, "prod": "test_loc_api", "src": "baidu_loc_api", "key": "XXXXXXXXXXXXXXXXXXXXXXXXXXX", "body": [{ "bts": "460,0,4189,8869,-63", "output": "JSON", "accesstype": 0, "macs":"70:ba:ef:d0:87:91,-42,|70:ba:ef:d1:0e:01,-45,|70:ba:ef:cc:98:11,-56,|dc:fe:18:c9:94:ce,-87,|58:60:5f:68:d8:30,-89,|94:d9:b3:cf:a2:db,-91,|30:fc:68:ac:c6:ae,-91,|c8:3a:35:32:48:c8,-94,", "imei": "xxxxxxxxxxxxxxx", "ctime": "1551178833", "nearbts":"460,0,4189,33989,-81|460,0,4189,8868,-83|460,0,4189,33988,-84|460,0,4189,239,-86|460,0,4189,32659,-98|460,0,4189,8867,-99", "cdma": 0, "need_rgc": "Y", "network": "GPRS" }, { "accesstype": 0, "imei": "xxxxxxxxxxxxxxx", "clientip": "232.111.11.240", "cdma": 0, "imsi": "xxxxxxxxxxxxxxx", "network": "GPRS", "bts": "510,11,25182,40081,-83", "macs": "e0:36:76:e8:11:78,-18,1", "coor": "bd09ll", "output": "JSON", "ctime": "1551178833", "need_rgc": "Y" }, { "accesstype": 0, "imei": "xxxxxxxxxxxxxxx", "cdma": 0, "imsi": "xxxxxxxxxxxxxxx", "network": "GSM", "bts": "460,0,4163,21297934,-124", "nearbts": "460,0,-1,-1,13|460,0,-1,-1,29", "macs":"C8:E7:D8:33:B4:7C,-52,73cun|8C:A6:DF:DF:4B:14,-54,nolimit|E4:6F:13:CC:15:41,-57,weizhiweikeyong|E4:6F:13:CC:15:40,-64,WZWIT|66:14:4B:55:C8:48,-69,CMCC|54:B1:21:A6:81:D5,-73,HUAWEI-E5573-81D5|02:6B:E7:92:B1:73,-76,VANS|20:F4:1B:B6:9F:46,-78,ydnc", "coor": "GCJ02", "output": "JSON", "ctime": "1551178833", "need_rgc": "Y" } ] }
完整响应示例如下:
{ "errcode": 0, "msg": "Query success.", "body": [ { "type": 2, "location": "116.298457,39.848625", "radius": 41, "country": "中国", "province": "北京市", "city": "北京市", "citycode": "131", "district": "丰台区", "road": "丰台南路44号", "ctime": "1551178833", "indoor": "1", "error": 0 }, { "type": 4, "location": "107.614218,-6.941022", "radius": 111, "country": "Indonesia", "province": "Jawa Barat", "city": "Bandung City", "citycode": "34544", "district": "", "road": "Jalan Sriwijaya", "ctime": "1551178833", "indoor": "0", "error": 0 }, { "type": 2, "location": "116.352743,39.941695", "radius": 15, "country": "中国", "province": "北京市", "city": "北京市", "citycode": "131", "district": "西城区", "road": "西直门外大街1号院-3号", "ctime": "1551178833", "bldg": "bjxcqkdmall", "bldgid": "1266783613064577023", "bldgname": "凯德MALL(西直门嘉茂店)", "floor": "f4", "indoor": "1", "error": 0 } ] }
状态码 | 错误描述 |
0 | 正常 |
101 | Missing field : body (size should > 0 && < 3) |
102 | Request is empty |
103 | 参数错误,错误详情请见“msg”字段 |
104 | Unexpected err, please contact with us |
601 | Failed to authenticate for lack of AK |
700 | Failed to authenticate for invaid AK : ${key}(key校验失败) |
710 | Failed to authenticate for invaid IP : ${ip} (服务端IP校验失败) |
711 | APP SN校验失败。当用户请求的SN和服务端计算出来的SN不相等的时候提示SN校验失败。可考虑在控制台-我的应用中将AK的请求校验方式改为IP白名单 |
740 | Failed to authenticate for api loc is forbidden.(服务被禁用,一般不会出现) |
752 | Failed to authenticate for bad user.(非法用户) |
760 | Failed to authenticate for servive is not exist(服务不存在,一般不会出现) |
761 | Failed to authenticate for servive is off the assembly line(服务已下线,一般不会出现) |
801 | Failed to authenticate for exceeding total quota(总用量超限,一般不会出现) |
802 | Failed to authenticate for exceeding daily quota(${quota_num}) (日用量超限) |
901 | Failed to authenticate for exceeding concurrency(${min_quota}) (分钟并发超限) |
902 | Failed to authenticate for exceeding concurrency(${min_quota}) (日用量与分钟并发均超限) |
其他500+错误 | Failed to authenticate for unexpected error, please contact with us |
750 | Failed to authenticate for user is not exist |
751 | Failed to authenticate for user is deleted by yourself |
使用PostMan测试接口可参考下图:
每一个开发者帐号只有申请权限后才可使用该服务;
服务相关配额及并发请访问开发者权益页面查看。
如果您的应用为Android Native App,建议使用Android定位SDK,定位效果相当、且无任何使用配额及并发量的限制。
您可以在控制台申请权限后使用该服务。
智能硬件定位API服务与其他API服务一样,具有每天使用配额和并发次数的限制。您可以在控制台申请权限后购买配额及并发量。
智能硬件API适用于智能硬件可穿戴设备、车载等完成地图、轨迹、路线规划等功能,目前有一定的配额和并发次数限制,需要您在控制台申请权限才可以使用。 如果您是Android或iOS移动应用的开发者,我们推荐您使用Android/iOS端定位SDK产品。定位SDK产品是专门针对移动端Native App设计的,具有定位成功率高、速度快、精度高、流量小的特点。此外,SDK产品没有使用配额限制。
2016年3月25日
v1.0
2016年7月6日
V1.1
2016年11月2日
V1.2
2018年5月8日
V1.3
2018年5月18日
V1.4
2018年6月7日
V1.5
2018年6月19日
V1.6
2018年7月9日
V1.7
2018年11月10日
V1.8
2019年2月28日
V1.9
文档创建
响应体中新增ctime,用于批量请求中匹配请求体
补充AK申请相关流程
修正部分功能描述
域名迁移
增加响应字段 bldg(建筑物)、floor(楼层)、indoor(室内外)
增加响应字段bldgname(建筑物中文名称)
增加响应字段bldgid(建筑物对应id)
优化线上问题
新增postman说明