get($url); return Json::decode($result); } //计算距离 lng经度 lat纬度 ssh 2020.5.14 public static function calculateDistance($fromLnt, $fromLat, $toLnt, $toLat) { if (getenv('YII_ENV') == 'production') { $url = "https://restapi.amap.com/v5/direction/electrobike?key=" . self::$thirdMapKey . '&origin=' . $fromLnt . ',' . $fromLat . '&destination=' . $toLnt . ',' . $toLat; } else { $url = "http://restapi.amap.com/v5/direction/electrobike?key=" . self::$thirdMapKey . '&origin=' . $fromLnt . ',' . $fromLat . '&destination=' . $toLnt . ',' . $toLat; } $curl = new curl\Curl(); $result = $curl->get($url); $result = Json::decode($result); $distance = 0; if (!empty($result['status']) && $result['status'] == 1) { $path = $result['route']['paths'] ?? []; $current = $path[0] ?? []; $distance = $current['distance'] ?? 0; } return $distance; } //逆地址解析,根据经纬度解析出中文地址 ssh public static function resolveLocation($lat, $long) { $url = "https://apis.map.qq.com/ws/geocoder/v1/?location={$lat},{$long}&get_poi=0&key=" . self::$thirdMapKey; $curl = new curl\Curl(); $result = $curl->get($url); $result = Json::decode($result); return $result; } }