PHP获取实际地理位置信息

	//通过传递"经度"、"纬度"获取所在地理位置
	//$lat: 纬度
	//$lng: 经度
	//$BaiDu_AK: 百度AK密钥
	function GetLocation($lat, $lng, $BaiDu_AK) {
		$strLocation = "";
		$gps_data = file_get_contents("http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x=$lng&y=$lat");
		$arr = (array)json_decode($gps_data);
		$lat_t = $lng_t = "";
		if (!$arr['error']) {
			$lat_t = base64_decode($arr['y']);
			$lng_t = base64_decode($arr['x']);
		}
		if (strlen($lat_t) > 0 && strlen($lng_t) > 0) {
			$xml = new DOMDocument();
			$xml->load("http://api.map.baidu.com/geocoder/v2/?ak=$BaiDu_AK&callback=renderReverse&location=$lat_t,$lng_t&output=xml&pois=0");
			$result_s = $xml->getElementsByTagName("result");
			foreach($result_s as $result) {
				$formatted_address_s = $result->getElementsByTagName("formatted_address");
				$strLocation = $formatted_address_s->item(0)->nodeValue;
				break;
			}
		}
		if (strlen($strLocation) == 0) {
				$xml = new DOMDocument();
				$xml->load("http://maps.233.wiki/maps/api/geocode/xml?latlng=$lat,$lng&sensor=false&language=zh-CN");
				$result_s = $xml->getElementsByTagName("result");
				foreach($result_s as $result) {
					$formatted_address_s = $result->getElementsByTagName("formatted_address");
					$strLocation = $formatted_address_s->item(0)->nodeValue;
					break;
				}
		}
		return $strLocation;
	}
	echo GetLocation("39.935377", "119.600492", "自己的百度AK");