百度地图API 解析经纬度

输入:

Array
 ( [0] => 
 	Array ( [location] => latitude:23.177896137949592 longitude:113.3254380141534 ) 
 ) 

输出:

广东省广州市白云区沙太路133号|广鹰科技创新园西158米|元岗,兴华,沙河

代码:

	public function count_location($location)
	{
			preg_match_all("/[1-9]\d*\.\d*|0\.\d*[1-9]\d*/",$location[0]['location'],$out, PREG_PATTERN_ORDER);
			// echo  $val1[0]['uid'].'  '.$out[0][1].','.$out[0][0];
			 $url='http://api.map.baidu.com/geoconv/v1/?coords='.$out[0][1].','.$out[0][0].'&output=json&ak=111';
			 $result=file_get_contents($url);
             $data = json_decode($result);
			 $url='http://api.map.baidu.com/geocoder/v2/?location='. $data->result['0']->y.','. $data->result['0']->x.'&output=json&ak=111';  
             $result=file_get_contents($url);
             $data = json_decode($result);
			 if($data->status)
				$location1="未打开gps";
			 else
				$location1=$data->result->formatted_address.'|'.$data->result->sematic_description.'|'.$data->result->business;	
					
					
	}

你可能感兴趣的:(PHP)