Home  >  Article  >  Backend Development  >  Detailed explanation of examples of Baidu API calls in Python

Detailed explanation of examples of Baidu API calls in Python

PHP中文网
PHP中文网Original
2017-06-20 14:41:132677browse

Call Baidu API to obtain latitude and longitude information.

import requestsimport json
address = input('请输入地点:')
par = {'address': address, 'key': 'cb649a25c1f81c1451adbeca73623251'}
url = 'http://restapi.amap.com/v3/geocode/geo'
res = requests.get(url, par)
json_data = json.loads(res.text)
geo = json_data['geocodes'][0]['location']
longitude = geo.split(',')[0]
latitude = geo.split(',')[1]print(longitude,latitude)

In fact, it is not difficult to call the API. Here is the get method. The parameters are address and key. I found this key online and it should be usable. Run the code.

After processing the address of Embarrassing Encyclopedia, call the API to obtain the latitude and longitude, and then use the personal BDP to complete the map.

If you encounter any problems during the learning process or want to obtain learning resources, welcome to join the learning exchange group
626062078, let’s learn Python together!

The above is the detailed content of Detailed explanation of examples of Baidu API calls in Python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn