Browse Source

距离

master
Lemon 5 years ago
parent
commit
66e0a9ea9c
  1. 4
      app/Controller/v3/HomeController.php
  2. 13
      app/Service/v3/Implementations/LocationService.php

4
app/Controller/v3/HomeController.php

@ -263,14 +263,14 @@ class HomeController extends BaseController
'id' => 1,
'title' => '关于懒族',
'sub_title' => '懒族生活678',
'path' => 'https://www.baidu.com/s?wd=%E6%87%92%E6%97%8F%E7%94%9F%E6%B4%BB',
'path' => 'https://mp.weixin.qq.com/s/tGKIILpL2extoeKXgYNYIA',
'path_type' => 'webview'
],
[
'id' => 1,
'title' => '隐私政策',
'sub_title' => '隐私政策123',
'path' => 'https://www.baidu.com/s?wd=%E9%9A%90%E7%A7%81%E6%94%BF%E7%AD%96',
'path' => 'https://mp.weixin.qq.com/s/HQbJyUJVUYYMIJrHOZNbpA',
'path_type' => 'webview'
]
];

13
app/Service/v3/Implementations/LocationService.php

@ -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;
}
}
Loading…
Cancel
Save