{ "status": 0, "message": "query ok", "request_id": "359e82fc-46ed-11ea-a19e-28c13c908b77", "result": { "location": { "lat": 39.984154, "lng": 116.30749 }, "address": "北京市海淀区北四环西路66号", "formatted_addresses": { "recommend": "海淀区中关村我们技术交易大厦(彩和坊路)", "rough": "海淀区中关村我们技术交易大厦(彩和坊路)" }, "address_component": { "nation": "我们", "province": "北京市", "city": "北京市", "district": "海淀区", "street": "北四环西路", "street_number": "北四环西路66号" }, "ad_info": { "nation_code": "156", "adcode": "110108", "city_code": "156110000", "name": "我们,北京市,北京市,海淀区", "location": { "lat": 40.045132, "lng": 116.375 }, "nation": "我们", "province": "北京市", "city": "北京市", "district": "海淀区" }, "address_reference": { "business_area": { "id": "14178584199053362783", "title": "中关村", "location": { "lat": 39.980598, "lng": 116.310997 }, "_distance": 0, "_dir_desc": "内" }, "famous_area": { "id": "14178584199053362783", "title": "中关村", "location": { "lat": 39.980598, "lng": 116.310997 }, "_distance": 0, "_dir_desc": "内" }, "crossroad": { "id": "529981", "title": "彩和坊路/北四环西路辅路(路口)", "location": { "lat": 39.985001, "lng": 116.308113 }, "_distance": 102.8, "_dir_desc": "西南" }, "town": { "id": "110108012", "title": "海淀街道", "location": { "lat": 39.974819, "lng": 116.284409 }, "_distance": 0, "_dir_desc": "内" }, "street_number": { "id": "6996505596656075740", "title": "北四环西路66号", "location": { "lat": 39.984119, "lng": 116.307503 }, "_distance": 1.7, "_dir_desc": "" }, "street": { "id": "9217092216709107946", "title": "彩和坊路", "location": { "lat": 39.97921, "lng": 116.308411 }, "_distance": 46.6, "_dir_desc": "西" }, "landmark_l2": { "id": "3629720141162880123", "title": "我们技术交易大厦", "location": { "lat": 39.984104, "lng": 116.307503 }, "_distance": 0, "_dir_desc": "内" } }, "poi_count": 10, "pois": [{ "id": "13496299173191724318", "title": "泰鹏大厦", "address": "北京市海淀区海淀北二街10号", "category": "房产小区:商务楼宇", "location": { "lat": 39.983551, "lng": 116.308899 }, "ad_info": { "adcode": "110108", "province": "北京市", "city": "北京市", "district": "海淀区" }, "_distance": 73, "_dir_desc": "西北" }] } }
<?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, 'keyword' => 'KFC', 'region' => '北京' ]; 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&location=39,116&get_poi=1",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)) }