Home  >  Article  >  Backend Development  >  How to call map in Python

How to call map in Python

(*-*)浩
(*-*)浩Original
2019-07-03 10:15:574717browse

First of all, if you want to call Baidu Map API, you need to obtain a Baidu Map API key. Applying for a key is very simple. There are relevant links on the homepage of Baidu Maps API. Fill in the relevant information and Baidu will give you a key. The next step is to introduce Baidu Maps API

How to call map in Python

Steps: (Recommended learning: Python video tutorial)

Use python statements to obtain latitude and longitude through Baidu Map API

Build a function to capture latitude and longitude

Capture latitude and longitude

Generate HTML adapted format

Generate the corresponding format, and then copy it out.

Example:

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

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)

Note: Select the map in Functions and Services, click on the left to get the key, and then apply as required. Mobile phone and Baidu account and email authentication are required.

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

The above is the detailed content of How to call map 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