How to call Baidu map api in python

(*-*)浩
Release: 2019-06-22 14:13:08
Original
6401 people have browsed it

Application programming interface (API) is a set of predefined functions designed to provide applications and developers with the ability to access a set of routines based on certain software or hardware without having to access the source code or understand Details of the inner workings.

How to call Baidu map api in python

#First go to Baidu Map to apply to get the secret key ak. (Recommended learning: Python video tutorial)

The map API can convert our geographical location into longitude and latitude, or display our location based on longitude and latitude.

import requests
import json
import pprint
 
ak = 'm9umAdjKIi7WQdQ54DYR8N3yuIRB5YZ1'#ak需要去百度地图申请
address = input('请输入想要查询的地址')
 
url = 'http://api.map.baidu.com/geocoder/v2/?address={}&output=json&ak={}'.format(address,ak)
res = requests.get(url)
json_data = json.loads(res.text)
pprint.pprint(json_data)#美观打印数据结构
lat = json_data['result']['location']['lat']#经度
lng = json_data['result']['location']['lng']#纬度
print(lat,lng)
Copy after login

For more Python related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of How to call Baidu map api in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!