接口地址:http://api.map.baidu.com/reverse_geocoding/v3/ |
---|
返回格式:json/xml |
请求方式:get |
请求示例:http://api.map.baidu.com/reverse_geocoding/v3/?ak=您的ak&output=json&coordtype=wgs84ll&location=31,121 |
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
location | float | 必填 | 根据经纬度坐标获取地址 |
ak | string | 必填 | 用户申请注册的key,自v2开始参数修改为“ak”,之前版本参数为“key”申请ak 扫码关注公众号 |
coordtype | string | 选填 | 坐标的类型,目前支持的坐标类型包括:bd09ll(百度经纬度坐标)、bd09mc(百度米制坐标)、gcj02ll(国测局经纬度坐标,仅限中国)、wgs84ll( GPS经纬度) 坐标系说明 |
ret_coordtype | string | 选填 | 添加后返回国测局经纬度坐标或百度米制坐标 |
radius | int | 选填 | poi召回半径,允许设置区间为0-1000米,超过1000米按1000米召回 |
sn | string | 选填 | 若用户所用ak的校验方式为sn校验时该参数必须 |
output | string | 选填 | 输出格式为json或者xml |
callback | string | 选填 | 将json格式的返回值通过callback函数返回以实现jsonp功能 |
extensions_poi | string | 选填 | 0,不召回pois数据;1,返回pois数据,默认显示周边1000米内的poi,注意:若需访问境外POI,需申请「逆地理编码境外POI」服务权限,请提交工单申请 |
extensions_road | string | 选填 | 当取值为true时,召回坐标周围最近的3条道路数据。区别于行政区划中的street参数(street参数为行政区划中的街道,和普通道路不对应) |
extensions_town | string | 选填 | 当取值为true时,行政区划返回乡镇级数据(仅国内召回乡镇数据)。默认不访问 |
language | string | 选填 | 指定召回的新政区划语言类型 |
language_auto | int | 选填 | 是否自动填充行政区划。注意:多语言需申请「逆地理编码境外POI」服务权限,请提交工单申请 |
名称 | 类型 | 说明 |
---|---|---|
status | int | 返回结果状态值, 成功返回0,其他值请查看下方返回码状态表 |
location | object | 经纬度坐标 |
formatted_address | string | 结构化地址信息 |
business | string | 坐标所在商圈信息,如 "人民大学 |
addressComponent | object | 国外行政区划 |
pois | object | 周边poi数组 |
parent_poi | object | 请求中的坐标与所归属区域面的相对位置关系 |
sematic_description | string | 当前位置结合POI的语义化结果描述 |
cityCode | int | 百度定义的城市id(正常更新与维护,但建议使用adcode) |
{
"status": 0,
"result": {
"location": {
"lng": 121.50989077799084,
"lat": 31.22932842411674
},
"formatted_address": "上海市黄浦区中山南路187",
"business": "外滩,陆家嘴,董家渡",
"addressComponent": {
"country": "中国",
"country_code": 0,
"country_code_iso": "CHN",
"country_code_iso2": "CN",
"province": "上海市",
"city": "上海市",
"city_level": 2,
"district": "黄浦区",
"town": "",
"adcode": "310101",
"street": "中山南路",
"street_number": "187",
"direction": "东北",
"distance": "91"
},
"pois": [],
"roads": [],
"poiRegions": [],
"sematic_description": "",
"cityCode": 289
}
}
错误码 | 说明 |
---|---|
0 | 服务请求正常召回 |
1 | 服务器内部错误 |
2 | 请求参数非法 |
3 | 权限校验失败 |
4 | 配额校验失败 |
5 | ak不存在或者非法 |
102 | 不通过白名单或者安全码不对 |
2xx | 无权限 |
3xx | 配额错误 |
<?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/reverse_geocoding/v3/?output=json&coordtype=wgs84ll&location=31.225696563611,121.49884033194&output=json&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;
}
}