Baidu map api simple application of (a): POI retrieval

Before using, you need to sign up for a Baidu map developer account, it is best to apply for a certification for the use of quotas and higher concurrency limit.

After registration, apply for an application to obtain a ak (key), and fill in the ip address whitelist. (Here I use 0.0.0.0/0, but check their ip ip Baidu always seem to say that I am wrong, forget it)

Principle Baidu map api that you want to input parameters (call function, specific parameters) embodied in the url, the url open, returns a json file (also xml file, but the default json, and easy), this json the paper contains a variety of information you want.

The most commonly used is the poi (point of interests) retrieved, we as an example, try the site search function.

Import JSON
 Import Requests
 Import PANDAS AS PD 

feature_data = [] 
Query = ' bank ' 
ZX = [31.15,121.41 ]; 
YS = [31.30,121.60 ] 
ZB = STR (ZX [0]) + ' , ' + STR (ZX [ 1]) + ' , ' + str (YS [0]) + ' , ' + str (YS [1 ]) 
AK = ' my key (this was confidential, or the daily limit may be directly used by others) ' 


DEF url_to_file (URL): 
    Data = requests.get(url).text
    hjson = json.loads(data)
    if hjson['message'] == 'ok':
        datalist = hjson['results']
        for each in datalist:
            feature_data.append(each)


for k in range(100):
    url = 'http://api.map.baidu.com/place/v2/search?query=' + query + '&bounds=' + zb + '&page_size=20&page_num=' + str(
        k) + '&output=json&ak=' + ak
    url_to_file(url)

feature = pd.DataFrame(feature_data)
feature.to_csv(str(query)+'_按矩形.csv')

However, open csv file, garbled.

Then open the file with Notepad -> Save As -> change a character encoding (utf-8 I will become ANSI), it can be opened.

 

Guess you like

Origin www.cnblogs.com/maoerbao/p/11461557.html