Quellcode durchsuchen

逆地址解析

shish vor 5 Jahren
Ursprung
Commit
2dfe22e5e9
1 geänderte Dateien mit 38 neuen und 28 gelöschten Zeilen
  1. 38 28
      common/components/mapUtil.php

+ 38 - 28
common/components/mapUtil.php

@@ -1,6 +1,6 @@
 <?php
 /**
- * User: ssh
+ * User: shish
  * Date: 2019/11/20
  * Time: 23:21
  */
@@ -12,32 +12,42 @@ use yii\helpers\Json;
 
 class mapUtil
 {
-	
-	public static $txMapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
-	
-	//腾讯地图关键词输入提醒 ssh 2020.1.21
-	//https://lbs.qq.com/webservice_v1/guide-suggestion.html
-	public static function suggestion($region, $keyword)
-	{
-		$url = "http://apis.map.qq.com/ws/place/v1/suggestion/?region={$region}&keyword={$keyword}&key=" . self::$txMapKey;
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$result = Json::decode($result);
-		return $result;
-	}
-	
-	//计算距离 lng经度 lat纬度 ssh 2020.5.14
-	public static function calculateDistance($fromLnt, $fromLat, $toLnt, $toLat)
-	{
-		$url = "https://apis.map.qq.com/ws/distance/v1/?mode=driving&from={$fromLat},{$fromLnt}&to={$toLat},{$toLnt}&key=" . self::$txMapKey;
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$result = Json::decode($result);
-		$distance = 0;
-		if (isset($result['status']) && $result['status'] == 0) {
-			$distance = isset($result['result']['elements'][0]['distance']) ? $result['result']['elements'][0]['distance'] : 0;
-		}
-		return $distance;
-	}
+
+    public static $txMapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
+
+    //腾讯地图关键词输入提醒 ssh 2020.1.21
+    //https://lbs.qq.com/webservice_v1/guide-suggestion.html
+    public static function suggestion($region, $keyword)
+    {
+        $url = "http://apis.map.qq.com/ws/place/v1/suggestion/?region={$region}&keyword={$keyword}&key=" . self::$txMapKey;
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $result = Json::decode($result);
+        return $result;
+    }
+
+    //计算距离 lng经度 lat纬度 ssh 2020.5.14
+    public static function calculateDistance($fromLnt, $fromLat, $toLnt, $toLat)
+    {
+        $url = "https://apis.map.qq.com/ws/distance/v1/?mode=driving&from={$fromLat},{$fromLnt}&to={$toLat},{$toLnt}&key=" . self::$txMapKey;
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $result = Json::decode($result);
+        $distance = 0;
+        if (isset($result['status']) && $result['status'] == 0) {
+            $distance = isset($result['result']['elements'][0]['distance']) ? $result['result']['elements'][0]['distance'] : 0;
+        }
+        return $distance;
+    }
+
+    //逆地址解析,根据经纬度解析出中文地址 shish
+    public static function resolveLocation($lat, $long)
+    {
+        $url = "https://apis.map.qq.com/ws/geocoder/v1/?location={$lat},{$long}&get_poi=0&key=" . self::$txMapKey;
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $result = Json::decode($result);
+        return $result;
+    }
 
 }