接口地址:https://restapi.amap.com/v3/geocode/regeo |
---|
返回格式:json |
请求方式:get |
请求示例:https://restapi.amap.com/v3/geocode/regeo?key=你的key&location=116.310003,39.991957 |
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
key | string | 必填 | 高德Key 扫码关注公众号 |
location | string | 必填 | 经纬度坐标,经纬度小数点后不要超过6位 |
poitype | string | 选填 | 返回附近POI类型 |
radius | string | 选填 | 搜索半径 |
extensions | string | 选填 | 返回结果控制 |
batch | bool | 选填 | 批量查询控制 |
roadlevel | int | 选填 | 道路等级 |
sig | string | 选填 | 参数根据ASCII码排序,再拼接key值,最后MD5,如:sig=md5(a=23&b=12&c=67&d=48&f=8bbbbb) |
output | string | 选填 | 返回数据格式类型,默认json |
callback | string | 选填 | 回调函数,callback值是用户定义的函数名称,此参数只在output参数设置为JSON时有效 |
homeorcorp | int | 选填 | 是否优化POI返回顺序 |
名称 | 类型 | 说明 |
---|---|---|
见json返回实例 | - | - |
{
"status": "1",
"regeocode": {
"addressComponent": {
"city": [],
"province": "北京市",
"adcode": "110108",
"district": "海淀区",
"towncode": "110108015000",
"streetNumber": {
"number": "5号",
"location": "116.310454,39.9927339",
"direction": "东北",
"distance": "94.5489",
"street": "颐和园路"
},
"country": "中国",
"township": "燕园街道",
"businessAreas": [{
"location": "116.303364,39.97641",
"name": "万泉河",
"id": "110108"
},
{
"location": "116.314222,39.98249",
"name": "中关村",
"id": "110108"
},
{
"location": "116.294214,39.99685",
"name": "西苑",
"id": "110108"
}
],
"building": {
"name": "北京大学",
"type": "科教文化服务;学校;高等院校"
},
"neighborhood": {
"name": "北京大学",
"type": "科教文化服务;学校;高等院校"
},
"citycode": "010"
},
"formatted_address": "北京市海淀区燕园街道北京大学"
},
"info": "OK",
"infocode": "10000"
}
错误码 | 说明 |
---|---|
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/geocode/regeo?key=youkey&location=116.310003,39.991957';
/**
* 获取 逆地理编码 结果
* @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;
}
}