This is a simple latitude and longitude conversion into specific address information, supporting international and domestic latitude and longitude conversion.
The effect is shown in the following illustration:
function XmlToArray2 ($xml) {
//convert XML to array
$array _data = Json_decode (Json_encode (simplexml_load_string ($ XML, ' SimpleXMLElement ', libxml_nocdata), true);
return $array _data;
}
function Geturljson ($url, $type = 0) {
$ch = Curl_init ($url);
curl_setopt ($ch, Curlopt_returntransfer, true); Gets the data returns
curl_setopt ($ch, Curlopt_binarytransfer, True),//////$RS returns the fetch data when the Curlopt_returntransfer is enabled
= Curl_ EXEC ($ch);
if ($type = = 1) {
$rs = Json_decode ($rs, True)
;
return $rs;
}
function GetLocation ($longitude, $latitude) {
$rs = "";
if ($longitude && $latitude) {
$url = "???"; /Please download source view
$xml = Geturljson ($url);
$XMLARR = XmlToArray2 ($xml);
$rs = $xmlArr [' result '] [' addresscomponent '];
}
return $rs;
}
Print out address related information
$longitude = ' 31.218372 ';
$latitude = ' 121.471197 ';
$rs = GetLocation ($longitude, $latitude);
Print_r ($RS);
Here can refer to the demo address: two of the material net _ Baidu map based on latitude and longitude to obtain national, State and other address related information