/**
* https://lbs.qq.com/webservice_v1/guide-gcoder.html
* 获取附近的地址
*/
public function getNearbyAddress()
{
// 118.275162,33.963008 (宿迁市)
if (!$lng = $_POST['lng']) { // 经度
$this->json->E('缺少参数');
}
if (!$lat = $_POST['lat']) { // 纬度
$this->json->E('缺少参数');
}
$distance = Func::getDistance($lng, $lat, '118.275162', '33.963008');
if ($distance > 90) { // 超出范围,按宿迁地址计算
$lng = '118.275162';
$lat = '33.963008';
}
$page = $_POST['page'] ?: 1;
// lng 118.34590148925781
// lat 33.95277786254883
$apiHttp = 'https://apis.map.qq.com/ws/geocoder/v1/?location=' . $lat . ',' . $lng . '&key=' . C('TENCENT_LOCATION_KEY') . '&get_poi=1&poi_options=address_format=short;radius=10000;page_size=40;page_index=' . $page . ';policy=1';
$result = Http::doGet($apiHttp);
$result = json_decode($result, true);
if ($result['status'] === 0) {
$this->json->S($result['result']);
} else {
$this->json->E('获取失败');
}
}
/**
* 获取搜索的地址
*/
public function getSearchAddress()
{
// 118.275162,33.963008 (宿迁市)
if (!$lng = $_POST['lng']) { // 经度
$this->json->E('缺少参数');
}
if (!$lat = $_POST['lat']) { // 纬度
$this->json->E('缺少参数');
}
$distance = Func::getDistance($lng, $lat, '118.275162', '33.963008');
if ($distance > 90) { // 超出范围,按宿迁地址计算
$lng = '118.275162';
$lat = '33.963008';
}
if (!$keywords = $_POST['keywords']) { // 关键字
$this->json->E('请输入关键字');
}
$page = $_POST['page'] ?: 1;
// lng 118.34590148925781
// lat 33.95277786254883
$apiHttp = 'https://apis.map.qq.com/ws/place/v1/search?boundary=nearby(' . $lat . ',' . $lng . ',10000)&keyword=' . $keywords . '&page_size=40&page_index=' . $page . '&orderby=_distance&key=' . C('TENCENT_LOCATION_KEY');
$result = Http::doGet($apiHttp);
$result = json_decode($result, true);
if ($result['status'] === 0) {
$this->json->S($result['data']);
} else {
$this->json->E('获取失败');
}
}
/**
* 根据坐标获取城市
*/
public function getCityByCoord() {
if (!$lng = $_POST['lng']) { // 经度
$this->json->E('缺少参数');
}
if (!$lat = $_POST['lat']) { // 纬度
$this->json->E('缺少参数');
}
$apiHttp = 'https://apis.map.qq.com/ws/geocoder/v1/?location=' . $lat . ',' . $lng . '&key='.C('TENCENT_LOCATION_KEY').'&get_poi=0';
$result = Http::doGet($apiHttp);
$result = json_decode($result, true);
if ($result['status'] === 0) {
$city = $result['result']['address_component']['city'];
$this->json->S($city);
} else {
$this->json->E('获取失败');
}
}