|
|
|
@ -143,7 +143,7 @@ class LocationService implements LocationServiceInterface |
|
|
|
//获取骑行距离
|
|
|
|
public function getDistanceByTencent($lng1, $lat1, $lng2, $lat2) |
|
|
|
{ |
|
|
|
$url = 'https://apis.map.qq.com/ws/direction/v1/'; |
|
|
|
$url = 'https://apis.map.qq.com/ws/distance/v1/matrix/?mode='; |
|
|
|
/** |
|
|
|
* $tyep driving 驾车 walking 步行 bicycling 骑行 transit 公交 |
|
|
|
*/ |
|
|
|
@ -151,22 +151,19 @@ class LocationService implements LocationServiceInterface |
|
|
|
$key = config('map.tencent'); |
|
|
|
$client = new Client([ |
|
|
|
// Base URI is used with relative requests
|
|
|
|
'base_uri' => 'https://apis.map.qq.com/ws/direction/v1/bicycling/', |
|
|
|
'base_uri' => 'https://apis.map.qq.com/', |
|
|
|
// You can set any number of default request options.
|
|
|
|
'timeout' => 2.0, |
|
|
|
]); |
|
|
|
$response = $client->request('GET', $url.$type.'/?from='.$lat1.','.$lng1.'&to='.$lat2.','.$lng2.'&output=json&key='.$key); |
|
|
|
$response = $client->request('GET', $url.$type.'&from='.$lat1.','.$lng1.'&to='.$lat2.','.$lng2.'&output=json&key='.$key); |
|
|
|
$response = $response->getBody()->getContents(); |
|
|
|
$resultArr = json_decode($response,true); |
|
|
|
if($resultArr['status'] == 384) |
|
|
|
{ |
|
|
|
return 100; |
|
|
|
} |
|
|
|
if($resultArr['status'] > 0) |
|
|
|
{ |
|
|
|
throw new ErrorCodeException(ErrorCode::LOCATION_ERROR,$resultArr['message']); |
|
|
|
} |
|
|
|
$distance = $resultArr['result']['routes'][0]['distance']; |
|
|
|
var_dump($resultArr); |
|
|
|
$distance = $resultArr['result']['rows'][0]['elements'][0]['distance']; |
|
|
|
return $distance; |
|
|
|
} |
|
|
|
} |