|
|
@@ -19,7 +19,7 @@ class mapUtil
|
|
|
{
|
|
|
if (getenv('YII_ENV') == 'production') {
|
|
|
$url = "https://restapi.amap.com/v3/assistant/inputtips?city={$region}&keywords={$keyword}&key=" . self::$thirdMapKey;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$url = "http://restapi.amap.com/v3/assistant/inputtips?city={$region}&keywords={$keyword}&key=" . self::$thirdMapKey;
|
|
|
}
|
|
|
$curl = new curl\Curl();
|
|
|
@@ -30,13 +30,19 @@ class mapUtil
|
|
|
//计算距离 lng经度 lat纬度 ssh 2020.5.14
|
|
|
public static function calculateDistance($fromLnt, $fromLat, $toLnt, $toLat)
|
|
|
{
|
|
|
- $url = "https://apis.map.qq.com/ws/distance/v1/matrix/?mode=driving&from={$fromLat},{$fromLnt}&to={$toLat},{$toLnt}&key=" . self::$thirdMapKey;
|
|
|
+ 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 (isset($result['status']) && $result['status'] == 0) {
|
|
|
- $distance = isset($result['result']['rows'][0]['elements'][0]['distance']) ? $result['result']['rows'][0]['elements'][0]['distance'] : 0;
|
|
|
+ if (!empty($result['status']) && $result['status'] == 1) {
|
|
|
+ $path = $result['route']['paths'] ?? [];
|
|
|
+ $current = $path[0] ?? [];
|
|
|
+ $distance = $current['distance'] ?? 0;
|
|
|
}
|
|
|
return $distance;
|
|
|
}
|