$coords = "106.60591541666666,29.530784861111112";
$url='http://api.map.baidu.com/geoconv/v1/?coords='.$coords.'&from=1&to=5&ak=你的key';//百度提供的坐标转换接口
$url=str_replace(' ','',$url);//去除空格
//php的请求百度接口
$curl = curl_init();
//设置抓取的url
curl_setopt($curl, CURLOPT_URL,$url);
//设置头文件的信息作为数据流输出
curl_setopt($curl, CURLOPT_HEADER, 1);
//设置获取的信息以文件流的形式返回,而不是直接输出。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//执行命令
$response = curl_exec($curl);//接收百度接口返回的数据
//关闭URL请求
curl_close($curl);
// return $response;
$needle='{';
$m=strpos ( $response ,$needle ,0 );//截取返回json数据
$response_json=substr($response,$m ,strlen($response));//把字符串转为json数据
$responseArr=json_decode($response_json,true);
$lng = $responseArr["result"][0]['x'];
$lat = $responseArr["result"][0]['y'];
echo $lng.",".$lat;
其中$coords可以是多组坐标点,用分号隔开,例如:
$coords = "106.60591541666666,29.530784861111112;106.60591541666666,29.530784861111112";