Pārlūkot izejas kodu

动态选择范围

lizhen_gitee 7 mēneši atpakaļ
vecāks
revīzija
3cbb8311d4
2 mainītis faili ar 65 papildinājumiem un 2 dzēšanām
  1. 61 1
      application/api/controller/Topicdongtai.php
  2. 4 1
      application/common.php

+ 61 - 1
application/api/controller/Topicdongtai.php

@@ -12,7 +12,7 @@ use think\Exception;
  */
 class Topicdongtai extends Api
 {
-    protected $noNeedLogin = [];
+    protected $noNeedLogin = ['poi','poi2'];
     protected $noNeedRight = ['*'];
 
     //发布动态
@@ -930,6 +930,66 @@ class Topicdongtai extends Api
         $this->success('success',$list);
     }
 
+    //维智地图,POI搜索API
+    /*public function poi(){
+        $access_key = 'oLv7qgwJ5E4SdxSLvKLDRzdrkgQdLYV0';
+
+        $keyword = '人民广场';
+        $city_code = '';
+        $city = '临沂';
+        $page = input('page',1);
+
+        $url = 'https://api.newayz.com/location/scenario/v1/placesearch?name='.$keyword.'&access_key='.$access_key.'&city='.$city.'&page_index='.$page.'&page_size=10';
+
+        $header = ['Content-Type: application/json'];
+        $rs = curl_get($url,$header);
+        dump($rs);
+
+    }*/
+    //维智地图,POI搜索API
+    public function poi2(){
+        $access_key = 'oLv7qgwJ5E4SdxSLvKLDRzdrkgQdLYV0';
+
+        $longitude = input('longitude','');
+        $latitude  = input('latitude','');
+        $location  = $longitude.','.$latitude;
+
+        $keyword = input('keyword','');
+        $radius  = 1000;//周边半径
+        $page    = input('page',1);
+        $page_size = input('listrow',10);
+
+
+        $url = 'https://api.newayz.com/location/scenario/v1/nearbysearch?access_key='.$access_key.'&location='.$location.'&keywords='.$keyword.'&radius='.$radius.'&page_index='.$page.'&page_size='.$page_size;
+
+        $header = ['Content-Type: application/json'];
+        $rs = curl_get($url,$header);
+        $rs = json_decode($rs,true);
+
+        $result = [];
+        if(!empty($rs)){
+            foreach($rs as $key => $val){
+
+                if(!isset($val['geoPoint']) || empty($val['geoPoint'])){ continue; }
+                if(!isset($val['name']) || empty($val['name'])){ continue; }
+                if(!isset($val['address']['name']) || empty($val['address']['name'])){ continue; }
+
+                $location = explode(',',$val['geoPoint']);
+                if( !isset($location[0]) || !isset($location[1]) ){ continue; }
+
+                $result[] = [
+                    'longitude' => $location[0],
+                    'latitude'  => $location[1],
+                    'name'      => $val['name'],
+                    'address'   => $val['address']['name'],
+                ];
+            }
+        }
+
+//        $this->success(1,$rs);
+        $this->success(1,$result);
+
+    }
 
 
 }

+ 4 - 1
application/common.php

@@ -722,7 +722,7 @@ function curl_post($url, $data, $header = '', $timeOut = 0)
 /**
  * 发起HTTP GET请求
  */
-function curl_get($url)
+function curl_get($url,$header = '')
 {
     $oCurl = curl_init();
     if(stripos($url, "https://") !== FALSE) {
@@ -733,6 +733,9 @@ function curl_get($url)
     curl_setopt($oCurl, CURLOPT_TIMEOUT, 3);
     curl_setopt($oCurl, CURLOPT_URL, $url);
     curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
+    if($header != '') {
+        curl_setopt($oCurl, CURLOPT_HTTPHEADER, $header);
+    }
     $sContent = curl_exec($oCurl);
     $aStatus = curl_getinfo($oCurl);
     $error = curl_error($oCurl);