需求
用关键词查询一个范围内的地点。如半径5000米内的超市。使用高德地图API来实现。
程序
keyword = "超市"
location = "120.00,30.00"
radius = 5000
KEY = "xxxx"
url = f"https://restapi.amap.com/v3/place/around?key={KEY}&location={location}&keywords={keyword}&radius={radius}&output=json"
response = requests.get(url)
data = response.json()
content = ""
if data["status"] == "1":
for poi in data["pois"]:
content += f'{poi["name"]}, {poi["address"]}, {poi["adname"]}, {poi["cityname"]}'
else:
content += f'请求失败: {data["info"]}'
