以下是一个使用Python的示例代码,用于获取here.com的静态图像:
import requests
def get_static_map_image(api_key, lat, lon, zoom=10, width=500, height=500):
base_url = "https://image.maps.ls.hereapi.com/mia/1.6/mapview"
params = {
"apiKey": api_key,
"c": f"{lat},{lon}",
"z": zoom,
"w": width,
"h": height
}
response = requests.get(base_url, params=params)
if response.status_code == 200:
with open("static_map_image.png", "wb") as file:
file.write(response.content)
print("Static map image saved successfully!")
else:
print("Error occurred while fetching static map image.")
# 设置HERE API密钥
api_key = "YOUR_API_KEY"
# 设置地点的经纬度坐标
latitude = 40.7128
longitude = -74.0060
# 获取静态地图图像
get_static_map_image(api_key, latitude, longitude)
请确保安装了requests
库,可以使用以下命令进行安装:
pip install requests
以上代码将获取指定经纬度位置的静态地图图像,并将其保存为名为static_map_image.png
的文件。请将YOUR_API_KEY
替换为您自己的HERE API密钥。