谷歌静态地图API 允许在网页上嵌入谷歌地图图像,而无需JavaScript或任何动态页面加载。Google静态地图API服务根据通过标准HTTP请求发送的URL参数创建地图,并将地图作为可以在网页上显示的图像返回。
null
要使用这项服务,你必须需要一个API密钥,获取它的形式 在这里 .
注: 你需要在谷歌上创建账单账户,然后才能使用谷歌API。
所需模块:
import requests
以下是实施情况:
# Python program to get a google map # image of specified location using # Google Static Maps API # importing required modules import requests # Enter your api key here api_key = "_your_api_key_" # url variable store url # center defines the center of the map, # equidistant from all edges of the map. center = "Dehradun" # zoom defines the zoom # level of the map zoom = 10 # get method of requests module # return response object r = requests.get(url + "center =" + center + "&zoom =" + str (zoom) + "&size = 400x400&key =" + api_key + "sensor = false" ) # wb mode is stand for write binary mode f = open ( 'address of the file location ' , 'wb' ) # r.content gives content, # in this case gives image f.write(r.content) # close method of file object # save and close the file f.close() |
输出:
注: 要检查API密钥是否正常工作,请存储 r.content
在里面 .txt
文件,尽管另存为 .png
文件如果API密钥无效,API将返回此错误消息,而不是图像“Google Maps API服务器拒绝了您的请求。提供的API密钥无效”。
以下列表显示了在每个缩放级别可以看到的大致细节级别:
1 : World 5 : Landmass/continent 10 : City 15 : Streets 20 : Buildings
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END