• 收货地址管理,使用腾讯开放平台


    /**
     * 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('获取失败');
        }
    }
    
  • 相关阅读:
    MySQL的FORMAT函数用法规则
    jetbrains idea/webstorm等(注册,激活,破解码,一起支持正版,最新可用)(2017.3.16更新)【转】
    用户价值模型 CITE :https://www.jianshu.com/p/34199b13ffbc
    用户生命周期模型
    机器学习十大常用算法(CITE 不会停的蜗牛 ) interesting
    Linux 安装Oracle11g完整安装图文教程另附基本操作 (分享)
    oracle 命中率
    SQL学习总结笔记
    hash join
    Tomcat详细安装配置
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/12384645.html
Copyright © 2020-2023  润新知