接口地址:https://apis.map.qq.com/ws/coord/v1/translate |
---|
返回格式:json/jsonp |
请求方式:get |
请求示例:https://apis.map.qq.com/ws/coord/v1/translate?locations=39.12,116.83;30.21,115.43&type=3&key=yourkey |
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
key | string | 必填 | 开发密钥 扫码关注公众号 |
locations | string | 必填 | 预转换的坐标,支持批量转换, 格式:纬度前,经度后,纬度和经度之间用","分隔,每组坐标之间使用";"分隔; 批量支持坐标个数以HTTP GET方法请求上限为准 |
type | string | 必填 | 输入的locations的坐标类型 1 GPS坐标 2 sogou经纬度 3 baidu经纬度 4 mapbar经纬度 5 [默认]腾讯、google、高德坐标 6 sogou墨卡托 |
output | string | 选填 | 返回格式 |
callback | string | 选填 | JSONP方式回调函数 |
名称 | 类型 | 说明 |
---|---|---|
- | - | - |
{
"status": 0,
"message": "转换成功",
"locations": [{
"lng": 116.82339,
"lat": 39.114347
},
{
"lng": 115.423577,
"lat": 30.20378
}
]
}
错误码 | 说明 |
---|---|
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/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))
}