接口地址:https://apis.map.qq.com/ws/place/v1/search |
---|
返回格式:json/jsonp |
请求方式:get |
请求示例:https://apis.map.qq.com/ws/place/v1/search?key=yourkey&keyword=KFC&boundary=region |
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
key | string | 必填 | 开发密钥 扫码关注公众号 |
keyword | string | 必填 | POI搜索关键字,用于全文检索字段 keyword=酒店,注意键值要进行URL编码(推荐encodeURI) |
boundary | string | 必填 | 搜索地理范围 |
filter | string | 选填 | 筛选条件 |
orderby | string | 选填 | 排序,目前仅周边搜索(boundary=nearby)支持按距离由近到远排序 |
page_size | string | 选填 | 每页条目数,最大限制为20条 |
page_index | string | 选填 | 第x页,默认第1页 |
output | string | 选填 | 返回格式 |
callback | string | 选填 | JSONP方式回调函数 |
名称 | 类型 | 说明 |
---|---|---|
- | - | - |
{
"status": 0,
"message": "query ok",
"count": 645,
"request_id": "0582430312537b0a3e2169adc538187a7a29bcf3bc25",
"data": [{
"id": "11431737744703354058",
"title": "肯德基(羊坊店)",
"address": "北京市海淀区复兴路戊12号恩菲科技大厦1楼",
"tel": "010-63950271",
"category": "美食:小吃快餐",
"type": 0,
"location": {
"lat": 39.90604,
"lng": 116.32168
},
"ad_info": {
"adcode": 110108,
"province": "北京市",
"city": "北京市",
"district": "海淀区"
}
}],
"region": {
"title": "北京市"
}
}
错误码 | 说明 |
---|---|
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/place/v1/search';
}
/**
* 获取结果
* @return string
*/
public function getResult(){
$paras = [
'key' => $this->appKey,
'keyword' => 'KFC',
'boundary' => 'region(北京,0)'
];
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/place/v1/search"
APIKEY = "your key"
)
func main() {
queryUrl := fmt.Sprintf("%s?key=%s&keyword=KFC&boundary=region",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))
}