美文网首页
php调用百度地图接口,根据经纬度获取城市

php调用百度地图接口,根据经纬度获取城市

作者: 风度翩翩的程序猿 | 来源:发表于2022-03-03 15:23 被阅读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;
    }

相关文章

网友评论

      本文标题:php调用百度地图接口,根据经纬度获取城市

      本文链接:https://www.haomeiwen.com/subject/bafurrtx.html