https://api.map.baidu.com/locapi/v2
//POST请求
参数名称 | 字段含义 | 数据类型 | 备注 |
---|---|---|---|
key | 用户唯一标识,用户可在API控制台申请,应用类型建议选择服务端 | string | 必填 |
src | 定位请求来源,厂商标识,比如(baidu),开发者可自定义 | string | 必填 |
prod | 产品线名称,比如(baiduwatch),开发者可自定义 | string | 必填 |
ver | 申请服务版本号,目前只提供1.0服务 | string | 必填 |
trace | 是否开启trace,若为true,则将定位记录到鹰眼(暂不开通) | bool | 必填 |
参数名称 | 字段含义 | 数据类型 | 备注 |
---|---|---|---|
accesstype | 移动端接入网络方式 可选值: | int | 必填 |
smac | 手机mac码 默认值:无 | string | 非必选,但建议填写 |
imei | 移动设备识别码 | string | 必选 |
clientip | 移动网关IP 默认值:无 | string | 非必选,但建议填写 |
cdma | 是否为cdma。 非cdma:0; cdma:1 默认值为:0 | int | 非必选,但建议填写 |
imsi | 移动用户识别码 默认值:无 | string | 非必选,但建议填写 |
gps | 手机GPS数据 | string | accesstype=2时,必选 |
network | 无线网络类型 GSM/GPRS/EDGE/HSUPA/HSDPA/WCDMA (注意大写) | string | accesstype=0时,必选 |
tel | 手机号码 | string | 非必选 |
bts | 基站信息,非CDMA格式为:mcc, mnc,lac,cellid,signal;其中lac,cellid必须填写,signal如无法获取请填写50,前两位mcc, mnc 如无法获取,请填写-1 | string | accesstype=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 个 以内的方可正常定位。 | string | accesstype=1时,必选 |
bleand | 已连接蓝牙mac信息(仅限Android),mac;rssi;时间戳,mac之间使用“|”分隔。如:AC233F69320C;61;756457296|AC233F693444;61;756457294|…. | string | 非必选 |
blelp | 定位初始值(当系统为Android,希望有蓝牙定位,但无macs字段时,该字段必填,有macs字段时可不填,坐标系为wgs84坐标;当系统为Ios,希望有蓝牙定位,该字段必填,坐标系为wgs84坐标),格式如下:纬度|经度。如:31.306286|121.300841|unknow | string | 非必选 |
bleios | 扫到的蓝牙数据(仅限Ios),格式如下:uuid_major_minor_距离;rssi;时间| uuid_major_minor_距离;rssi;时间|… | string | 非必选 |
coor | 可指定坐标系(GCJ02|BD09LL),注意大写。 | string | 非必选 |
output | 返回数据格式类型(注意大写) 可选值:JSON, XML 默认值:JSON 一期只支持JSON | string | 非必选 |
ctime | 客户端时间戳 | string | 必选 |
need_rgc | 返回地址信息,默认不返回 | string | 非必选 |
need_poi | 返回周边Poi信息,默认不返回 | string | 非必选 |
sema | 返回附近的Poi名称,默认不返回 | string | 非必选 |
need_sub | 返回地铁状态信息,默认不返回 | string | 非必选 |
结果字段 | 字段含义 | 类型 |
---|---|---|
type | 定位类型,0:没有得到定位结果;1:gps 定位结果;2:wifi定位结果;3:混合定位 结果;4:基站定位结果;5:其他-- | int |
location | 定位经纬度(经度,纬度) | string |
radius | 定位精度半径,单位:米 | int |
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 |
poi | 定位附近的poi名称(具体名称) | string |
aptag | 在XXX附近信息 | string |
paname | 附近POI名称 | list |
sub_station | getTraffic返回subway时返回,所处地铁站点名称 | string |
sub_line | getTraffic返回subway时返回,所处地铁线路名称、如果是多线路可同时返回 | string |
输入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(); // 初始化curlcurl_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); // 运行curlif (!$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" | 是 |
{"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 | 正常 |
101 | Missing field : body (size should > 0 && < 3)(缺少请求body,请补充后重试) |
102 | Request is empty(请求为空) |
103 | 参数错误,错误详情请见“msg”字段 |
104 | Unexpected err, please contact with us(其他错误,请通过工单与我们联系) |
601 | Failed to authenticate for lack of AK(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(用户被删除,鉴权失败) |
上一篇
下一篇
本篇文章对您是否有帮助?