接口地址:https://restapi.amap.com/v3/traffic/status/rectangle |
---|
返回格式:json |
请求方式:get |
请求示例:https://restapi.amap.com/v3/traffic/status/rectangle?rectangle=116,39;116,39&key=key |
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
key | string | 必填 | 高德Key 扫码关注公众号 |
rectangle | string | 必填 | 代表此为矩形区域查询 |
level | int | 选填 | 道路等级 |
sig | string | 选填 | 参数根据ASCII码排序,再拼接key值,最后MD5,如:sig=md5(a=23&b=12&c=67&d=48&f=8bbbbb) |
extensions | string | 选填 | 返回结果控制 |
output | string | 选填 | 返回数据格式类型,默认json |
callback | string | 选填 | 回调函数,callback值是用户定义的函数名称,此参数只在output参数设置为JSON时有效 |
名称 | 类型 | 说明 |
---|---|---|
见json返回实例 | - | - |
{
"status": "1",
"info": "OK",
"infocode": "10000",
"trafficinfo": {
"description": "北三环路:自东向西畅通。",
"evaluation": {
"expedite": "91.67%",
"congested": "8.33%",
"blocked": "0.00%",
"unknown": "0.00%",
"status": "2",
"description": "轻度拥堵"
}
}
}
错误码 | 说明 |
---|---|
10001 | key不正确或过期 |
10002 | 没有权限使用相应的服务或者请求接口的路径拼写错误 |
10003 | 访问已超出日访问量 |
10004 | 单位时间内访问过于频繁 |
10005 | IP白名单出错,发送请求的服务器IP不在IP白名单内 |
10006 | 绑定域名无效 |
10007 | 数字签名未通过验证 |
10008 | MD5安全码未通过验证 |
10009 | 请求key与绑定平台不符 |
10010 | IP访问超限 |
10011 | 服务不支持https请求 |
10012 | 权限不足,服务请求被拒绝 |
10013 | Key被删除 |
10014 | 云图服务QPS超限 |
10015 | 受单机QPS限流限制 |
10016 | 服务器负载过高 |
10017 | 所请求的资源不可用 |
10019 | 使用的某个服务总QPS超限 |
10020 | 某个Key使用某个服务接口QPS超出限制 |
10021 | 来自于同一IP的访问,使用某个服务QPS超出限制 |
10022 | 某个Key,来自于同一IP的访问,使用某个服务QPS超出限制 |
10023 | 某个KeyQPS超出限制 |
20000 | 请求参数非法 |
20001 | 缺少必填参数 |
20002 | 请求协议非法 |
20003 | 其他未知错误 |
20011 | 询坐标或规划点(包括起点、终点、途经点)在海外,但没有海外地图权限 |
20012 | 查询信息存在非法内容 |
20800 | 规划点(包括起点、终点、途经点)不在中国陆地范围内 |
20801 | 划点(起点、终点、途经点)附近搜不到路 |
20802 | 路线计算失败,通常是由于道路连通关系导致 |
20803 | 起点终点距离过长 |
300** | 服务响应失败 |
<?php
/**
* Created by PhpStorm.
* User: FZS
* Time: 2019/7/20 17:50
*/
//----------------------------------
// 矩形区域交通态势 调用类
//----------------------------------
class freeApi{
private $apiUrl = 'https://restapi.amap.com/v3/traffic/status/rectangle?rectangle=116,39;116,39&key=key';
/**
* 获取 矩形区域交通态势 结果
* @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;
}
}