https://api.map.baidu.com/locapi/v2?ver=1.0&trace=false&prod=test_loc_api&src=baidu_loc_api&key=您的ak
//post请求
参数名称 | 字段含义 | 数据类型 | 备注 |
---|---|---|---|
key | 用户唯一标识,用户可在申请,应用类型建议选择服务端 | 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时,必选 |
coor | 可指定坐标系(gcj02|bd09ll),注意大写。 | string | 非必选 |
output | 返回数据格式类型(注意大写) 可选值:json, xml 默认值:json 一期只支持json | string | 非必选 |
ctime | 客户端时间戳 | string | 必选 |
need_rgc | 返回地址信息,默认不返回 | 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 |
输入ak可生成包含ip/sn校验方式的代码
<?php// 此处填写你在控制台-应用管理-创建应用后获取的ak$ak ='您的ak';// 发起一个http get请求,并返回请求的结果// $url字段为请求的地址// $param字段为请求的参数functionrequest_get($url ='', $param =array()){if(empty($url)||empty($param)){returnfalse;}$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['ver']='1.0';$param['trace']='false';$param['prod']='test_loc_api';$param['src']='baidu_loc_api';$param['key']='您的ak // post请求';$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(用户被删除,鉴权失败) |
上一篇
下一篇
本篇文章对您是否有帮助?