Because the API to connect Baidu map, and then through the latitude to get location information, but the location of the information is embedded in the URL by the latitude and longitude, generated XML file, because it is online, at that time, it was thought to get the data inside without downloading, because the use of code download is available to download, But the download to the specific path always fails, first put the failed code, someone can see, may be able to wake up, or there is a better way.
1<?PHP2 Define($filePath, ' d:\\phpstudy\\www\\children\\gprs\\ ');3 $filename= ' http://api.map.baidu.com/geocoder?location=30.990998,103.645966&output=xml&key= 28bcdd84fae25699606ffad27f8da77b ';4 //Types of files5 Header(' Content-type:text/xml ');6 //Download the displayed name7 Header("Content-disposition:attachment; filename={$filePath}.map.xml ");8 //ReadFile ("$filename");9 $content=file_get_contents(Map.XML);Ten Var_dump($content);
At this time can not var_dump out the data inside, just when the connection is opened automatically downloaded to the browser default download place, I set the file path at the beginning of the completely useless, the file or downloaded to the browser default download folder.
Later on the Internet to see, is directly to get the data in the URL, do not download down, sure enough is more convenient ah.
1<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>2<?PHP3 $content=file_get_contents(' http://api.map.baidu.com/geocoder?location=30.990998,103.645966&output=json&key= 28bcdd84fae25699606ffad27f8da77b ');4 $json= Json_decode ($content,true);5 Var_dump($json);6 $address=$json[' Result '] [' Formatted_address '];7 Echo' <br><br><br><br> ';8 Echo $address;
The first row of meta if not add the words will be garbled, now according to the link to obtain the latitude and longitude location of the specific position.
If the array display is not intuitive, you can simply click to view the source code and then get the desired location information based on the key.
PHP gets data from online XML