如何用Mapbox静态图片API URL替换Google地图静态API URL?

问题描述 投票:0回答:1

我在看一段代码,使用谷歌地图静态API请求下载日间图像。问题是我没有计费账户,无法免费使用谷歌地图静态API(因为我目前没有获得信用卡)。

我正在考虑使用MapBox静态图像API,它可以让用户免费进行初始API调用.我无法将谷歌地图API URL代码转换为MapBox API URL代码。任何形式的帮助或指导可能是非常有用的。

这里是使用谷歌地图静态API进行调用的代码。

class ImageryDownloader:
def __init__(self, access_token):
    self.access_token = access_token
    self.url = 'https://maps.googleapis.com/maps/api/staticmap?center={},{}&zoom={}&size=400x400&maptype=satellite&key={}'

def download(self, lat, long, zoom):
    res = requests.get(self.url.format(lat, long, zoom, self.access_token))
    # server needs to make image available, takes a few seconds
    if res.status_code == 403:
        return 'RETRY'
    assert res.status_code < 400, print(f'Error - failed to download {lat}, {long}, {zoom}')
    image = plt.imread(BytesIO(res.content))
    return image

然后进行API调用

lat = 38.441332
lon = -105.234751

access = open(ACCESS_TOKEN_DIR, 'r').readlines()[0]
url = "https://maps.googleapis.com/maps/api/staticmap?center={},{}&zoom=14&size=400x400&maptype=satellite&key={}".format(lat, lon, access)
res = requests.get(url)
plt.imshow(plt.imread(BytesIO(res.content)))

链接到MapBox API文档。MapBox静态图像API

python api google-maps url mapbox
1个回答
0
投票

你的问题相当广泛,所以我无法分享一个非常具体的答案。但值得注意的是,你可以在Mapbox的文档网站上使用静态图像游戏场。https:/docs.mapbox.complaygroundstatic. 这个工具提供了一个用于构建静态图像API请求的GUI。


⚠️免责声明:我目前在Mapbox工作⚠️。

© www.soinside.com 2019 - 2024. All rights reserved.