接口地址:https://apis.map.qq.com/ws/geocoder/v1 |
---|
返回格式:json/jsonp |
请求方式:get |
请求示例:https://apis.map.qq.com/ws/geocoder/v1/?address=北京市海淀区彩和坊路海淀西大街74号&key=yourkey |
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
key | string | 必填 | 开发密钥 扫码关注公众号 |
address | string | 必填 | 地址 |
region | string | 选填 | 指定地址所属城市 |
output | string | 选填 | 返回格式:支持JSON/JSONP,默认JSON |
callback | string | 选填 | JSONP方式回调函数 |
名称 | 类型 | 说明 |
---|---|---|
- | - | - |
{
"status": 0,
"message": "query ok",
"result": {
"title": "海淀西大街74号",
"location": {
"lng": 116.30676,
"lat": 39.98296
},
"ad_info": {
"adcode": "110108"
},
"address_components": {
"province": "北京市",
"city": "北京市",
"district": "海淀区",
"street": "海淀西大街",
"street_number": "74"
},
"similarity": 0.8,
"deviation": 1000,
"reliability": 7,
"level": 9
}
}
错误码 | 说明 |
---|---|
310 | 请求参数信息有误 |
311 | Key格式错误 |
306 | 请求有护持信息请检查字符串 |
110 | 请求来源未被授权 |
<?php
class freeApi{
private $apiUrl;
private $appKey;
public function __construct($appKey){
$this->appKey = $appKey;
$this->apiUrl = 'https://apis.map.qq.com/ws/geocoder/v1';
}
/**
* 获取结果
* @return string
*/
public function getResult(){
$paras = [
'key' => $this->appKey,
'address' => '北京市海淀区彩和坊路海淀西大街74号',
];
return $this->freeApiCurl($this->apiUrl,$paras);
}
/**
* 请求接口返回内容
* @param string $url [请求的URL地址]
* @param string $params [请求的参数]
* @return string
*/
public function freeApiCurl($url,$params=[]){
if (!$params) return false;
return file_get_contents($url.'?'.http_build_query($params));
}
}
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
)
const (
APIURL = "https://apis.map.qq.com/ws/geocoder/v1"
APIKEY = "your key"
)
func main() {
queryUrl := fmt.Sprintf("%s?key=%s&address=北京市海淀区彩和坊路海淀西大街74号",APIURL,APIKEY)
resp, err := http.Get(queryUrl)
if err != nil {
log.Println(err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}