Client.php
1.17 KB
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
<?php
/**
*
* @author tongdesheng
*
*/
class YHMUtils_Lbs_Client {
/**
* 通过经纬度获取省、市、区
* @param float $lat
* @param float $lng
*/
public static function getAddrFromLatlng($lat, $lng) {
$url = YHMConfig_Lbs::API_URL . '?ak=' . YHMConfig_Lbs::AK . '&location=' . $lat .',' . $lng
. '&output=json&pois=0';
$httpClient = new Q_Utils_Http($url);
$httpClient->request('get');
$retData = array();
if($httpClient->getStatus() == 200) {
$strRet = $httpClient->getBody(); //{"status":0,"result":{"location":{"lng":116.44897797499,"lat":39.926069092316},"formatted_address":"北京市朝阳区南营房七条7号","business":"朝外,朝阳门,东大桥","addressComponent":{"city":"北京市","district":"朝阳区","province":"北京市","street":"南营房七条","street_number":"7号"},"cityCode":131}}
$addrData = json_decode($strRet, true);
if($addrData['status'] == 0) {
$retData = array(
'province' => $addrData['result']['addressComponent']['province'],
'city' => $addrData['result']['addressComponent']['city'],
'area' => $addrData['result']['addressComponent']['district']
);
}
}
return $retData;
}
}