Python 从谷歌地图API(staticmap)处理图像
我正试图从谷歌地图API获取图像,更准确地说是从staticmap API获取图像。Python 从谷歌地图API(staticmap)处理图像,python,google-maps-api-3,Python,Google Maps Api 3,我正试图从谷歌地图API获取图像,更准确地说是从staticmap API获取图像。 问题是,在Google Maps的其他API中,您可以选择是希望从JSON还是XML的API中获取信息,但在staticmap(返回图像)中,您似乎无法选择。 所以我不知道如何处理URL提供的图像,因为我不知道它是如何编码的 这就是我想要做的: import requests url = ("https://maps.googleapis.com/maps/api/staticmap?size=400x400
问题是,在Google Maps的其他API中,您可以选择是希望从JSON还是XML的API中获取信息,但在staticmap(返回图像)中,您似乎无法选择。 所以我不知道如何处理URL提供的图像,因为我不知道它是如何编码的 这就是我想要做的:
import requests
url = ("https://maps.googleapis.com/maps/api/staticmap?size=400x400path=weight:3%7Ccolor:orange%7Cenc:polyline_data")
response = requests.get(url)
print(response.json())
鉴于该信息可能不在Json中,因此会引发以下错误:
ValueError: Expecting value: line 1 column 1 (char 0)
希望您对如何将响应转化为有用的内容有任何建议 嗯。。。好吧,你想得太多了 staticmap(返回图像) 是的,既然你是对的,这就是你所说的 下面是它的一个演示。我使用的例子来自
我能够解决问题,以下是代码:
import requests
url = ("https://maps.googleapis.com/maps/api/staticmap?size=400x400path=weight:3%7Ccolor:orange%7Cenc:polyline_data")
r = requests.get(url)
image = r._content
with open("map.png","wb") as file: #with this you create a usable file .png
file.write(image)