根据经纬度获取地址
function getAddress($log,$lag){
if ($log && $lag){
$gwd = $lag.','.$log;
$baidu_apikey = M('System')->getFieldById(1,'baidu_apikey');
$file_contents = file_get_contents('http://api.map.baidu.com/geocoder/v2/?ak='.$baidu_apikey.'&location='.$gwd.'&output=json');
$rs = json_decode($file_contents,true);
$sheng = $rs['result']['addressComponent']['province'];
$shi = $rs['result']['addressComponent']['city'];
$qu = $rs['result']['addressComponent']['district'];
$address = $rs['result']['formatted_address'];
}
根据地址获取经纬度
//根据地址获取经纬度
function getLonLat($address){
$ak =M('system')->where(['id'=>'1'])->getField('baidu_apikey');
$api = 'http://api.map.baidu.com/geocoder/v2/? ak='.$ak.'&output=json&address='.$address;
$position = file_get_contents($api);
$position = json_decode($position, true);
$array = $position['result']['location'];
$position = array($array['lng'],$array['lat']);//经度,纬度
return $position;
}