接口地址:http://api.map.baidu.com/parking/search |
---|
返回格式:json |
请求方式:get |
请求示例:http://api.map.baidu.com/parking/search?location=116.313064,40.048541&coordtype=bd09ll&ak=你的ak |
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
ak | string | 必填 | 用户申请注册的key,自v2开始参数修改为“ak”,之前版本参数为“key”申请ak 扫码关注公众号 |
location | string | 必填 | 需查询周边推荐上车点的位置坐标 |
sn | string | 选填 | 若用户所用ak的校验方式为sn校验时该参数必须 |
coord_type | string | 选填 | 请求参数中坐标的类型 |
radius | string | 选填 | 设置检索周边推荐上车点半径 |
名称 | 类型 | 说明 |
---|---|---|
status | int | 返回结果状态值 |
message | string | 对API访问状态值的英文说明,如果成功返回"ok",并返回结果字段,如果失败返回错误说明 |
recommendstops | object | 推荐上下车点信息 |
{
"status": 0,
"message": "OK",
"recommendStops": [{
"name": "北京发那科机电有限公司-东北门",
"address": "信息路9号",
"distance": 31.0,
"bd09ll_x": 116.31336097180909,
"bd09ll_y": 40.04875989119061,
"gcj02ll_x": 116.30689819521366,
"gcj02ll_y": 40.04270884908236,
"id": "dbdfc729e22930d622f01734"
}, {
"name": "信息路/上地六街路口",
"address": "",
"distance": 91.0,
"bd09ll_x": 116.3131004632112,
"bd09ll_y": 40.04920864731756,
"gcj02ll_x": 116.30663946101423,
"gcj02ll_y": 40.0431529706092,
"id": "48c13c08c88ffcb94557260b"
}, {
"name": "奎科科技大厦-正门",
"address": "信息路甲9号东门",
"distance": 122.0,
"bd09ll_x": 116.31381910761918,
"bd09ll_y": 40.047965930748038,
"gcj02ll_x": 116.3073531765317,
"gcj02ll_y": 40.0419230556821,
"id": "d8d9f0057005489ff503b8bf"
}]
}
错误码 | 说明 |
---|---|
- | - |
<?php
/**
* Created by PhpStorm.
* User: FZS
* Time: 2019/9/3 23:10
*/
//----------------------------------
// 调用类
//----------------------------------
class freeApi{
private $ak;
private $apiUrl;
public function __construct($ak){
$this->ak = $ak;
$this->apiUrl = 'http://api.map.baidu.com/parking/search?location=116.313064,40.048541&coordtype=bd09ll&ak='.$this->ak;
}
/**
* 获取结果
* @return array
*/
public function getResult(){
return $this->freeApiCurl($this->apiUrl);
}
/**
* 请求接口返回内容
* @param string $url [请求的URL地址]
* @param string $params [请求的参数]
* @param int $ipost [是否采用POST形式]
* @return string
*/
public function freeApiCurl($url,$params=false,$ispost=0){
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
curl_setopt( $ch, CURLOPT_USERAGENT , 'free-api' );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
if( $ispost )
{
curl_setopt( $ch , CURLOPT_POST , true );
curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
curl_setopt( $ch , CURLOPT_URL , $url );
}
else
{
if($params){
curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
}else{
curl_setopt( $ch , CURLOPT_URL , $url);
}
}
$response = curl_exec( $ch );
if ($response === FALSE) {
return false;
}
curl_close( $ch );
return $response;
}
}