Baidu Map According to the latitude and longitude to obtain national, State, and other address related information

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.