{ "status": 0, "message": "转换成功", "locations": [{ "lng": 116.82339, "lat": 39.114347 }, { "lng": 115.423577, "lat": 30.20378 } ] }
<?php class freeApi{ private $apiUrl; private $appKey; public function __construct($appKey){ $this->appKey = $appKey; $this->apiUrl = 'https://apis.map.qq.com/ws/coord/v1/translate'; } /** * 获取结果 * @return string */ public function getResult(){ $paras = [ 'key' => $this->appKey, 'locations' => '39.12,116.83;30.21,115.43', 'type' => '3', ]; 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/coord/v1/translate" APIKEY = "your key" ) func main() { queryUrl := fmt.Sprintf("%s?key=%s&locations=39.12,116.83;30.21,115.43&type=3",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)) }