PHP根据地址逆向解析经纬度

function getLoLa($add)
{

	$baiduAK = 'https://api.map.baidu.com/geocoding/v3/?address=' . $add . '&output=json&ak=11Z8uiP8kIz6AG0Vjiwzbc5f9Ii0cdHd&callback=showLocation';
	$lola    = file_get_contents($baiduAK);

	return $lola;

}

function strRe($str)
{

	$b = str_replace('showLocation&&showLocation', '', $str);
	$b = str_replace('(', '', $b);
	$b = str_replace(')', '', $b);
	$c = json_decode($b, true);
	return $c;

}


echo "<pre>";
$a = strRe(getLoLa('宁波市鄞州区泰康中路558号'));
//var_dump($a);
echo $a["result"]["location"]["lng"];
echo "<br>";
echo $a["result"]["location"]["lat"];

//var_dump($a);
/*echo "<hr>";
var_dump($a);*/
发布了81 篇原创文章 · 获赞 14 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_41290949/article/details/103906252