高德地图开发平台提供了丰富的API接口,可以方便地进行地图数据的开发和分析。在商业分析数据采集中,使用高德地图开发平台的周边查询功能可以快速获取周边商圈、小区等信息,为商业决策提供数据支持。
针对您的需求,我建议采用以下方案:
具体操作步骤如下:
注:(上述内容由讯飞星火AI生成)
高德开放平台是高德地图推出的开放式服务平台,为开发者提供了多项能力,包括地图开发工具、位置云计算和位置大数据等。其中,地图开发工具包括API/SDK,快捷的位置云计算是云图,权威的位置大数据是高德位智。此外,高德开放平台还提供了Web服务API,向开发者提供HTTP接口,开发者可通过这些接口使用各类型的地理数据服务。
您可以在高德开放平台上注册成为开发者并创建应用,以获取Key来使用各项服务 。登录https://lbs.amap.com/,首先进行账号与Key的申请,注册成为高德开发者需要分三步:
第一步,注册高德开发者;
第二步,去控制台创建应用;
第三步,获取Key。
具体可参看下图,在开发者控制台上,可以设置、查看、监控各项服务。
开发文档中定义的webAPI搜索服务API是一类简单的HTTP接口,提供多种查询POI信息的能力,其中包括关键字搜索、周边搜索、多边形搜索、ID查询四种筛选机制。
适用场景:
URL:https://restapi.amap.com/v3/place/text?parameters
请求方式:GET
方参考:搜索API:https://lbs.amap.com/api/webservice/guide/api/search
第 1 步:申请”Web服务API”密钥(key)
第 2 步:拼接HTTP请求URL
第一步申请的key需作为必填参数一同发送
第 3 步:接收HTTP请求返回的数据(JSON或XML格式),解析数据。
import requests
import math
import time
# 解析API返回结果
def getnote(ret_dat):
neighborhoods_note = []
for j in range(0, len(ret_dat['pois'])):
neighborhoods = ret_dat['pois'][j]['name']
address = ret_dat['pois'][j]['address']
location = ret_dat['pois'][j]['location']
adname = ret_dat['pois'][j]['adname']
cityname = ret_dat['pois'][j]['cityname']
neighborhoodstype = ret_dat['pois'][j]['type']
business_area = ret_dat['pois'][j]['business_area']
tmp = [neighborhoods,neighborhoodstype, business_area,location,adname,cityname,address]
neighborhoods_note.append(tmp)
return neighborhoods_note
# 输入数据文件名称,经度,纬度,半径
def surroundingFormats(filename, longitude, latitude, radius):
# 周边搜索
url = 'https://restapi.amap.com/v3/place/around?'
url = url + 'key=' + key
location = '&location=' + str(longitude) + ',' + str(latitude)
keywords = '&keywords=小区'
radius = '&radius=' + str(radius)
offset = '&offset=20' # 默认20个,多了,可能返回出错
page = '&page='
url = url + location + keywords + radius + offset
neighborhoods_note = []
try:
query_url = url + page + str(1) + '&extensions=all'
response = requests.get(url=query_url, timeout=30)
ret_dat = response.json()
count = int(ret_dat['count'])
neighborhoods_note = neighborhoods_note + getnote(ret_dat)
pages = math.ceil(count/20)
# 给网络反馈时间,暂停3秒
time.sleep(3)
for i in range(2,pages+1):
query_url = url + page + str(i) + '&extensions=all'
response = requests.get(url=query_url, timeout=30)
ret_dat = response.json()
# API返回的数量,与实际可查询到的数据,可能不一致,以实际返回的为准
if len(ret_dat['pois'])==0:
break
neighborhoods_note = neighborhoods_note + getnote(ret_dat)
# 给网络反馈时间,暂停3秒
time.sleep(3)
print('降低网络服务压力,暂停3秒')
except requests.exceptions.ConnectionError:
ret_msg = '网络接口连接超时'
except:
print("高德地图周边查询异常错误", requests.exceptions)
# 列表转换为字符串列表,用于保存为文件(csv格式)
neighborhood_line = []
for v in neighborhoods_note:
ss = ''
for s in v:
# 返回实际数据无,内容为[],判断是list,而转换为空字符串''
if type(s)==list:
s = ''
if len(ss) ==0:
ss = s
else:
ss = ss + ',' + s
ss = ss + '\n'
neighborhood_line.append(ss)
with open(fileName,'a+',encoding='utf-8') as file:
file.writelines(neighborhood_line)
使用Python实现周边商业环境信息查询可以采用高德地图开发平台的API接口,具体步骤如下:
优势特点:
问题: