1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the light/apistore. |
5
|
|
|
* |
6
|
|
|
* (c) lichunqiang <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace light\apistore\apis; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @see http://apistore.baidu.com/apiworks/servicedetail/473.html |
16
|
|
|
*/ |
17
|
|
|
class Distance extends Api |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
private $address = 'http://apis.baidu.com/apistore/distance/waypoints?'; |
23
|
|
|
|
24
|
|
|
private $supportCoordTypes = [ |
|
|
|
|
25
|
|
|
'bd09ll', //百度墨卡托坐标, 默认 |
26
|
|
|
'bd09mc', |
27
|
|
|
'gcj02', //经过国测局加密的坐标 |
28
|
|
|
'wgs84', //gps获取的坐标 |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* If $queryParams is string: |
33
|
|
|
* 需要测距的点的经纬度坐标;需传入两个或更多的点。 |
34
|
|
|
* 两个点之间用 “; ”进行分割开,单个点的经纬度用“,”分隔开; |
35
|
|
|
* 例如: waypoints=118.77147503233,32.054128923368;116.3521416286, 39.965780080447;116.28215586757,39.965780080447. |
36
|
|
|
* |
37
|
|
|
* Can set [[coord_type]], so $queryParams is array |
38
|
|
|
* |
39
|
|
|
* @param string|array $queryParams |
40
|
|
|
* |
41
|
|
|
* @return mixed |
42
|
|
|
*/ |
43
|
3 |
|
public function get($queryParams) |
44
|
|
|
{ |
45
|
3 |
|
$params = []; |
46
|
3 |
|
if (!isset($queryParams['coord_type'])) { |
47
|
1 |
|
$params['coord_type'] = 'bd09ll'; |
48
|
1 |
|
} |
49
|
3 |
|
if (is_string($queryParams)) { |
50
|
1 |
|
$params['waypoints'] = $queryParams; |
51
|
1 |
|
} else { |
52
|
2 |
|
$params = array_merge($params, $queryParams); |
53
|
|
|
} |
54
|
|
|
//must return json. |
55
|
3 |
|
$params['output'] = 'json'; |
56
|
|
|
|
57
|
3 |
|
return $this->fetch($this->address . http_build_query($params)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
3 |
|
protected function _parseResponse($result) |
64
|
|
|
{ |
65
|
3 |
|
$result = json_decode($result, true); |
66
|
3 |
|
if ('Success' == $result['status']) { |
67
|
|
|
return [ |
68
|
1 |
|
'errcode' => 0, |
69
|
1 |
|
'errmsg' => 'success', |
70
|
1 |
|
'data' => $result['results'], |
71
|
1 |
|
]; |
72
|
|
|
} |
73
|
|
|
|
74
|
2 |
|
return ['errcode' => 1, 'errmsg' => $result['status']]; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.