浏览器版本低!无法浏览完整内容,建议升级或更换浏览器。

所有文档

智能硬件定位

智能硬件定位
下载开发文档
API服务地址

https://api.map.baidu.com/locapi/v2?ver=1.0&trace=false&prod=test_loc_api&src=baidu_loc_api&key=您的AK
//POST请求

请求头
参数名称字段含义数据类型备注
key

用户唯一标识,用户可在API控制台申请,应用类型建议选择服务端

string必填
src定位请求来源,厂商标识,比如(baidu),开发者可自定义string必填
prod产品线名称,比如(baiduwatch),开发者可自定义string必填
ver申请服务版本号,目前只提供1.0服务string必填
trace是否开启trace,若为true,则将定位记录 到鹰眼(暂不开通)bool必选
请求体
参数名称字段含义数据类型备注
accesstype

移动端接入网络方式 可选值:
移动接入网络:0
wifi接入网络:1
仅gps坐标转换:2
默认值:无

int必填
smac

手机mac码 默认值:无
此参数能够提高定位精度和准确度,且定位不到时可依据此参数进行跟踪排查,如没有则无法排查和跟踪问题。

string非必选,但建议填写
imei

移动设备识别码

string必选
clientip

移动网关IP 默认值:无
此参数能够提高定位精度和准确度,且定位不到时可依据此参数进行跟踪排查,如没有则无法排查和跟踪问题。

string非必选,但建议填写
cdma

是否为cdma。 非cdma:0; cdma:1 默认值为:0

int非必选,但建议填写
imsi

移动用户识别码 默认值:无
此参数能够提高定位精度和准确度,且定位不到时可依据此参数进行跟踪排查,如没有则无法排查和跟踪问题。

string非必选,但建议填写
gps

手机GPS数据
取值规则: 经度|纬度|半径。
坐标系类型:wgs84。

stringaccesstype=2时,必选
network无线网络类型 GSM/GPRS/EDGE/HSUPA/HSDPA/WCDMA (注意大写)stringaccesstype=0时,必选
tel手机号码string非必选
bts

基站信息,非CDMA格式为:mcc, mnc,lac,cellid,signal;其中lac,cellid必须填写,signal如无法获取请填写50,前两位mcc, mnc 如无法获取,请填写-1
CDMA格式为:sid,nid,bid,lon,lat,signal 其中lon,lat可为空,格式为:sid,nid,bid,,,signal
为保证定位效果,请尽量全部填写

stringaccesstype=0时,必选
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信息

stringaccesstype=1时,必选
coor

可指定坐标系(GCJ02|BD09LL),注意大写。
国内(包含港澳台)默认返回BD09LL坐标系。
国外不论填写任何坐标系类型,均返回WGS84坐标系。

string非必选
output返回数据格式类型(注意大写) 可选值:JSON, XML 默认值:JSON 一期只支持JSONstring非必选
ctime客户端时间戳string必选
need_rgc

返回地址信息,默认不返回
Y : 返回rgc结果 N : 不返回rgc结果

string非必选
need_poi

返回周边Poi信息,默认不返回
Y : 返回Poi结果 N : 不返回Poi结果

string非必选
sema

返回附近的Poi名称,默认不返回
aptagd:返回Poi结果

string非必选
特别说明: 为了尽可能地保证您定位结果的精确性以及问题追踪,除了必须填写的参数外,其他可以获得的参数尽可能的传入。 例如:WI-FI接入网络的情况下,也可以传入其对应的基站信息;而在移动接入网络的情况下,也可传入 WI-FI列表中 mac 信息(macs)。
返回参数
结果字段字段含义类型
type定位类型,0:没有得到定位结果;1:gps 定位结果;2:wifi定位结果;3:混合定位 结果;4:基站定位结果;5:其他--int
location定位经纬度(经度,纬度)string
radius定位精度半径,单位:米int
provincestring
citystring
citycode城市编码string
district县区 string
road道路名string
ctime客户端请求时间戳,批量请求时用于匹配服务端响应和客户端请求string
bldg建筑物简称string
bldgid建筑物IDstring
bldgname建筑物string
floor楼层string
indoor是否室内:0:室外 1:室内string
error定位是否成功 0: 成功 -1:失败int
poi定位附近的poi名称(具体名称) string
aptag在XXX附近信息string
paname附近POI名称list
示例代码
填写您的AK

输入AK可生成包含IP/SN校验方式的代码

<?php
// 此处填写你在控制台-应用管理-创建应用后获取的AK
$ak = '您的AK';
// 发起一个http get请求,并返回请求的结果
// $url字段为请求的地址
// $param字段为请求的参数
function request_get($url = '', $param = array()) {
if (empty($url) || empty($param)) {
return false;
}
$getUrl = $url . "?" . http_build_query($param);
$curl = curl_init(); // 初始化curl
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_URL, $getUrl); // 抓取指定网页
curl_setopt($curl, CURLOPT_TIMEOUT, 1000); // 设置超时时间1秒
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // curl不直接输出到屏幕
curl_setopt($curl, CURLOPT_HEADER, 0); // 设置header
$data = curl_exec($curl); // 运行curl
if (!$data) {
print("an error occured in function request_get(): " . curl_error($curl) . "\n");
}
curl_close($curl);
return $data;
}
// 请求地址
$url = 'https://api.map.baidu.com/locapi/v2';
// 构造请求参数
$param[''] = 'undefined';
$res = request_get($url, $param);
// 将原始返回的结果打印出来
print("请求的原始返回结果为:\n");
print($res . "\n");
?>
{
"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
}
]
}
在线运行
参数备注必选
ver
1.0
trace
false
prod
test_loc_api
src
baidu_loc_api
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"
POST BODY中请求参数填写示例
{
"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"
}
]
}
服务状态码
状态码错误描述
0正常
101Missing field : body (size should > 0 && < 3)(缺少请求body,请补充后重试)
102Request is empty(请求为空)
103参数错误,错误详情请见“msg”字段
104Unexpected err, please contact with us(其他错误,请通过工单与我们联系)
601Failed to authenticate for lack of AK(AK参数缺失)
700Failed to authenticate for invaid AK : ${key}(key校验失败)
710Failed to authenticate for invaid IP : ${ip} (服务端IP校验失败)
711APP SN校验失败。当用户请求的SN和服务端计算出来的SN不相等的时候提示SN校验失败。可考虑在控制台-我的应用中将AK的请求校验方式改为IP白名单
740Failed to authenticate for api loc is forbidden.(服务被禁用,一般不会出现)
752Failed to authenticate for bad user.(非法用户)
760Failed to authenticate for servive is not exist(服务不存在,一般不会出现)
761Failed to authenticate for servive is off the assembly line(服务已下线,一般不会出现)
801Failed to authenticate for exceeding total quota(总用量超限,一般不会出现)
802Failed to authenticate for exceeding daily quota(${quota_num}) (日用量超限)
901Failed to authenticate for exceeding concurrency(${min_quota}) (分钟并发超限)
902Failed to authenticate for exceeding concurrency(${min_quota}) (日用量与分钟并发均超限)
其他500+错误Failed to authenticate for unexpected error, please contact with us(鉴权失败,请与我们联系)
750Failed to authenticate for user is not exist(用户不存在,鉴权失败)
751Failed to authenticate for user is deleted by yourself(用户被删除,鉴权失败)

上一篇

使用准备

下一篇

室内定位

本篇文章对您是否有帮助?