PHP 调用百度api,将经纬度转化为地址

ak为百度地图账号的密钥
 
  
function address($lng,$lat){
    global $_W,$_GPC;
    // echo 'ok';exit;
    load()->func('communication');
    // $lng = '121.44836960129';
    // $lat = '31.183873508958';
    $url = 'http://api.map.baidu.com/geocoder/v2/?location='.$lat.','.$lng.'&output=json&pois=1&ak=erYKBghl7L2RxpHlsThEqXi0yyojaGDq';
    $result = ihttp_get($url);
    $result = json_decode($result['content'],true);
    // var_dump($result);exit;
    $arr = array();
    $arr['uniacid'] = $_W['uniacid'];
    $arr['openid'] = $_W['openid'];
    $arr['rid'] = $_GPC['rid'];
    $arr['lng'] = $lng;
    $arr['lat'] = $lat;
    $arr['time'] = time();
    $arr['date'] = date('Ymd');
    $arr['country'] = $result['result']['addressComponent']['country'];
    $arr['province'] = $result['result']['addressComponent']['province'];
    $arr['city'] = $result['result']['addressComponent']['city'];
    $arr['district'] = $result['result']['addressComponent']['district'];
    $arr['address'] = $result['result']['formatted_address'];
    $arr['business'] = $result['result']['business'];
    // var_dump($arr);exit;
 return $arr;
}

你可能感兴趣的:(PHP 调用百度api,将经纬度转化为地址)