118 lines
5.8 KiB
PHP
118 lines
5.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2021年11月15日
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\modules\api\controllers;
|
|
|
|
use app\modules\api\behaviors\LoginBehavior;
|
|
use app\components\Serializer;
|
|
use UniLbs\UniLbs;
|
|
|
|
class LbsController extends Controller
|
|
{
|
|
public function behaviors() {
|
|
return array_merge(parent::behaviors(),[
|
|
'login' => [
|
|
'class' => LoginBehavior::className(),
|
|
'ignore' => [
|
|
'api/lbs/address',
|
|
'api/lbs/location',
|
|
'api/lbs/place-suggestion',
|
|
]
|
|
]
|
|
]);
|
|
}
|
|
|
|
|
|
/**
|
|
* showdoc
|
|
* @catalog 地理相关/位置服务
|
|
* @title 逆地址解析
|
|
* @description 本接口提供由坐标到坐标所在位置的文字描述的转换。输入坐标返回地理位置信息
|
|
* @method get
|
|
* @url /api/lbs/address
|
|
* @param lat 必选 string 纬度
|
|
* @param lng 必选 string 经度
|
|
* @return {"code":0,"msg":"ok","data":{"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":"529961","title":"彩和坊路/海淀北一街(路口)","location":{"lat":39.983952,"lng":116.308228},"_distance":61.5,"_dir_desc":"西"},"town":{"id":"110108012","title":"海淀街道","location":{"lat":39.974819,"lng":116.284409},"_distance":0,"_dir_desc":"内"},"street_number":{"id":"595672509379194165901290","title":"北四环西路66号","location":{"lat":39.984089,"lng":116.308037},"_distance":45.8,"_dir_desc":""},"street":{"id":"","title":"北四环西路","location":{"lat":0,"lng":0},"_distance":103.7,"_dir_desc":"南"},"landmark_l2":{"id":"3629720141162880123","title":"中国技术交易大厦","location":{"lat":39.984104,"lng":116.307503},"_distance":0,"_dir_desc":"内"}}}}
|
|
* @return_param address string 地址描述
|
|
* @remark 经纬度为gcj02坐标
|
|
*/
|
|
public function actionAddress()
|
|
{
|
|
if(!\Yii::$app->request->isGet){
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$lat = \Yii::$app->request->get('lat');
|
|
$lng = \Yii::$app->request->get('lng');
|
|
$provider = "qqmap";
|
|
$key = \Yii::$app->params['mapKey'][$provider];
|
|
$uniLbs = new UniLbs($key,$provider);
|
|
$location = "{$lat},{$lng}";
|
|
$data = $uniLbs->plugin->getAddress(['location' => $location]);
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
/**
|
|
* showdoc
|
|
* @catalog 地理相关/位置服务
|
|
* @title 地址解析
|
|
* @description 本接口提供由文字地址到经纬度的转换能力,并同时提供结构化的省市区地址信息。
|
|
* @method get
|
|
* @url /api/lbs/location
|
|
* @param address 必选 string 位置
|
|
* @return {"code":0,"msg":"ok","data":{"title":"湖里区","location":{"lng":118.14577,"lat":24.5118},"ad_info":{"adcode":"350206"},"address_components":{"province":"福建省","city":"厦门市","district":"湖里区","street":"","street_number":""},"similarity":0.8,"deviation":1000,"reliability":1,"level":2},"response":{"status":0,"message":"query ok","result":{"title":"湖里区","location":{"lng":118.14577,"lat":24.5118},"ad_info":{"adcode":"350206"},"address_components":{"province":"福建省","city":"厦门市","district":"湖里区","street":"","street_number":""},"similarity":0.8,"deviation":1000,"reliability":1,"level":2}}}
|
|
* @return_param param param_type param_desc
|
|
* @remark 经纬度为gcj02坐标
|
|
*/
|
|
public function actionLocation()
|
|
{
|
|
if(!\Yii::$app->request->isGet){
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$provider = "qqmap";
|
|
$key = \Yii::$app->params['mapKey'][$provider];
|
|
$uniLbs = new UniLbs($key,$provider);
|
|
$data = \Yii::$app->request->get();
|
|
$data = $uniLbs->plugin->getLocation($data);
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
|
|
/**
|
|
* showdoc
|
|
* @catalog 地理相关/位置服务
|
|
* @title 关键词搜索提示
|
|
* @description 本接口提供关键词搜索提示
|
|
* @method get
|
|
* @url /api/lbs/place-suggestion
|
|
* @param location 必选 string 格式:纬度,经度
|
|
* @param keyword 必选 string 关键词
|
|
* @return {"code":0,"msg":"ok","data":{}}
|
|
* @return_param address string 地址描述
|
|
* @remark 参考文档<https://lbs.qq.com/service/webService/webServiceGuide/webServiceSuggestion>
|
|
*/
|
|
public function actionPlaceSuggestion()
|
|
{
|
|
if(!\Yii::$app->request->isGet){
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$provider = "qqmap";
|
|
$key = \Yii::$app->params['mapKey'][$provider];
|
|
$uniLbs = new UniLbs($key,$provider);
|
|
$data = \Yii::$app->request->get();
|
|
$data = $uniLbs->plugin->getPlaceSuggestion($data);
|
|
return $this->responseHandler($data);
|
|
}
|
|
}
|
|
|