php根据地址获取经纬度

2794
function get_map($address){
   $address = urlencode($address);
   $url = "http://api.map.baidu.com/geocoder/v2/?address=".$address."&output=json&ak=xxxxx";
   $address_data = file_get_contents($url);
   $json_data = json_decode($address_data);
   $lng = $json_data->result->location->lng;
   $lat = $json_data->result->location->lat;
   return ['lng'=>$lng,'lat'=>$lat];
}