| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- /**
- * User: shish
- * Date: 2019/11/20
- * Time: 23:21
- */
- namespace common\components;
- use linslin\yii2\curl;
- use yii\helpers\Json;
- class mapUtil
- {
-
- public static $txMapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
-
- //腾讯地图关键词输入提醒 shish 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纬度 shish 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;
- }
- }
|