| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- /**
- * User: ssh
- * Date: 2019/11/20
- * Time: 23:21
- */
- namespace common\components;
- use linslin\yii2\curl;
- use yii\helpers\Json;
- class mapUtil
- {
- public static $thirdMapKey = 'fe792548aa6e15ef4d5d501e508eaeae';
- public static function suggestion($region, $keyword)
- {
- if (getenv('YII_ENV') == 'production') {
- $url = "https://restapi.amap.com/v3/assistant/inputtips?city={$region}&keywords={$keyword}&key=" . self::$thirdMapKey;
- } else {
- $url = "http://restapi.amap.com/v3/assistant/inputtips?city={$region}&keywords={$keyword}&key=" . self::$thirdMapKey;
- }
- $curl = new curl\Curl();
- $result = $curl->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;
- }
- }
|