-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathBaiduMapClient.php
74 lines (60 loc) · 1.87 KB
/
BaiduMapClient.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
define ("BMC_DEBUG_MODE", false);
class BaiduMapClient
{
private $api_server_url;
private $auth_params;
public function __construct($api_key)
{
$this->api_server_url = "http://api.map.baidu.com/";
$this->auth_params = array();
$this->auth_params['key'] = $api_key;
}
//////////////////////////////////////////////////////////
// public mathods
//////////////////////////////////////////////////////////
public function place_search($query, $location, $radius)
{
return $this->call("place/search", array("query" => $query,
"location" => $location, "radius" => $radius, "output" => "json"));
}
public function geocoder_address($address)
{
return $this->call("geocoder", array("address" => $address, "output" => "json"));
}
public function geocoder_location($location)
{
return $this->call("geocoder", array("location" => $location, "output" => "json"));
}
//////////////////////////////////////////////////////////
// private mathods
//////////////////////////////////////////////////////////
protected function call($method, $params = array())
{
$params = array_merge($this->auth_params, $params);
$url = $this->api_server_url . "$method?".http_build_query($params);
if (BMC_DEBUG_MODE)
{
echo "REQUEST: $url" . "\n";
}
$ch = curl_init();
$this_header = array("content-type: text/javascript;charset=utf-8", "Accept-Charset:GBK,utf-8");
curl_setopt($ch, CURLOPT_HTTPHEADER, $this_header);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
//$data = mb_convert_encoding($data, "GBK", "UTF-8");
curl_close($ch);
$result = null;
if (!empty($data))
{
if (BMC_DEBUG_MODE)
{
echo "RETURN: " . $data . "\n";
}
$result = $data;//json_decode($data);
}
return $result;
}
}
?>