php调用百度地图接口,根据经纬度获取城市
2022-03-03 本文已影响0人
风度翩翩的程序猿
$url = "https://api.map.baidu.com/geocoder?location={$lon},{$lat}";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
$result = $this->XmlToArr($output);
public function XmlToArr($xml)
{
if ($xml == '') return '';
libxml_disable_entity_loader(true);
$arr = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
return $arr;
}