资讯专栏INFORMATION COLUMN

python 调用百度地图地点检索webAPI

SKYZACK / 1177人阅读

摘要:百度地图提供了开放的,使用方法服务右上角登陆账号点击获取密钥创建应用填写应用名称白名单然后复制例如然后直接上代码提供了种方式行政区划区域检索圆形区域检索矩形区域检索详情可见详情本文以为例市场深圳你的返回结果如下南山市场南新路广东省深

百度地图提供了开放的API,使用方法

WEB服务API

右上角登陆账号 -> 点击“获取密钥” -> “创建应用” -> 填写应用名称&白名单IP -> 然后复制AK(例如u2uqy7Gxui0XyBdcHLU0D3hQINLKokc0)

然后直接上代码
API提供了3种方式

1 行政区划区域检索 2 圆形区域检索 3 矩形区域检索

详情可见API详情
本文以 1,3为例

import requests

url = "http://api.map.baidu.com/place/v2/search"
querystring = {"query":"市场","region":"深圳","output":"json","ak":"你的ak","page_size":20,"page_num":0}
response = requests.request("GET", url, params=querystring)
r = response.json()
print(r["results"])
print(len(r["results"]))

返回结果如下

[{"name": "南山市场", "location": {"lat": 22.531757, "lng": 113.926754}, "address": "南新路2008", "province": "广东省", "city": "深圳市", "area": "南山区", "street_id": "d6df91c124f80073f7b9164d", "telephone": "13590117093", "detail": 1, "uid": "d6df91c124f80073f7b9164d"}, {"name": "笋岗文具玩具礼品批发市场", "location": {"lat": 22.564115, "lng": 114.114963}, "address": "宝安北路1025号", "province": "广东省", "city": "深圳市", "area": "罗湖区", "street_id": "28e700f171893318095cb34a", "telephone": "(0755)82268844", "detail": 1, "uid": "28e700f171893318095cb34a"}, {"name": "嶂背综合市场", "location": {"lat": 22.692344, "lng": 114.255645}, "address": "广东省深圳市龙岗区嶂背路216号", "province": "广东省", "city": "深圳市", "area": "龙岗区", "street_id": "4fc3161a8a8d3db03a13fd59", "detail": 1, "uid": "4fc3161a8a8d3db03a13fd59"}, {"name": "圳美市场", "location": {"lat": 22.796433, "lng": 113.951935}, "address": "广东省深圳市光明区光明新区喜乐多百货(康明路东)", "province": "广东省", "city": "深圳市", "area": "光明区", "street_id": "5ffe414874a5986d9fec2b06", "detail": 1, "uid": "5ffe414874a5986d9fec2b06"}, {"name": "牛湖农贸市场", "location": {"lat": 22.730088, "lng": 114.095257}, "address": "观澜镇牛湖村高尔夫大道旁", "province": "广东省", "city": "深圳市", "area": "龙华区", "street_id": "8f6d8c61968269a36c47605b", "detail": 1, "uid": "8f6d8c61968269a36c47605b"}, {"name": "坪山综合批发市场", "location": {"lat": 22.695807, "lng": 114.346117}, "address": "坪山区新区东纵路470号坪山批发市场公交车站旁六和工地", "province": "广东省", "city": "深圳市", "area": "坪山区", "street_id": "550fd5f96c6d9060931fc955", "detail": 1, "uid": "550fd5f96c6d9060931fc955"}, {"name": "坪西市场", "location": {"lat": 22.765712, "lng": 114.292258}, "address": "吉祥一路23号", "province": "广东省", "city": "深圳市", "area": "龙岗区", "street_id": "87248d96c13e62aa2806ce5a", "detail": 1, "uid": "87248d96c13e62aa2806ce5a"}, {"name": "友信冷冻食品城", "location": {"lat": 22.66691, "lng": 114.13473}, "address": "深圳市龙岗区南湾街道上李朗社区平吉大道78号", "province": "广东省", "city": "深圳市", "area": "龙岗区", "street_id": "d8ef3b08c51b727a58bbbc69", "telephone": "(0755)88263688", "detail": 1, "uid": "d8ef3b08c51b727a58bbbc69"}, {"name": "石岩新村综合市场", "location": {"lat": 22.679288, "lng": 113.930496}, "address": "深圳市宝安区王家庄市场1号301", "province": "广东省", "city": "深圳市", "area": "宝安区", "street_id": "593850fb068b9720df1e526b", "detail": 1, "uid": "593850fb068b9720df1e526b"}, {"name": "新陂头农贸市场", "location": {"lat": 22.807519, "lng": 113.948556}, "address": "深圳市光明区康弘路13号", "province": "广东省", "city": "深圳市", "area": "光明区", "detail": 1, "uid": "3a0a78bd2b341d86631809d9"}, {"name": "爱华肉菜市场", "location": {"lat": 22.544775, "lng": 114.098053}, "address": "爱华路47号", "province": "广东省", "city": "深圳市", "area": "福田区", "street_id": "b533ea4af6bb89584f6d4645", "telephone": "(0755)83620019", "detail": 1, "uid": "b533ea4af6bb89584f6d4645"}, {"name": "茜坑老村综合市场", "location": {"lat": 22.69478, "lng": 114.036412}, "address": "新区观澜", "province": "广东省", "city": "深圳市", "area": "龙华区", "street_id": "50fb64ff5a658e20e9f8531b", "telephone": "13885524446", "detail": 1, "uid": "50fb64ff5a658e20e9f8531b"}, {"name": "利民农贸批发市场", "location": {"lat": 22.742953, "lng": 114.289898}, "address": "广东省深圳市龙岗区深惠路1256号", "province": "广东省", "city": "深圳市", "area": "龙岗区", "street_id": "61f634f6fce2e8616a49f3aa", "detail": 1, "uid": "61f634f6fce2e8616a49f3aa"}, {"name": "龙岗第一市场", "location": {"lat": 22.73833, "lng": 114.287002}, "address": "广东省深圳市龙岗区龙岗第一市场(龙岗大道西)", "province": "广东省", "city": "深圳市", "area": "龙岗区", "street_id": "0143dd2b837c3381cf06a435", "detail": 1, "uid": "0143dd2b837c3381cf06a435"}, {"name": "回龙埔综合市场", "location": {"lat": 22.736316, "lng": 114.241372}, "address": "深圳市龙岗区龙平西路26", "province": "广东省", "city": "深圳市", "area": "龙岗区", "street_id": "d219bb1dc2beb792f50e775d", "telephone": "18926789088", "detail": 1, "uid": "d219bb1dc2beb792f50e775d"}, {"name": "公明综合市场", "location": {"lat": 22.786351, "lng": 113.899172}, "address": "光明区公明街道振明路145-5", "province": "广东省", "city": "深圳市", "area": "光明区", "detail": 1, "uid": "1eeed5464e94e5ebb5147f4c"}, {"name": "民治综合街市", "location": {"lat": 22.630651, "lng": 114.045652}, "address": "深圳市龙华区民治大道412", "province": "广东省", "city": "深圳市", "area": "龙华区", "street_id": "d0b8923fcf5d4bfbb5f42f5f", "detail": 1, "uid": "d0b8923fcf5d4bfbb5f42f5f"}, {"name": "荔园集贸批发市场", "location": {"lat": 22.698857, "lng": 114.141112}, "address": "平湖镇景秀三巷7号", "province": "广东省", "city": "深圳市", "area": "龙岗区", "street_id": "7ee3ccf7b8aed470047ce87c", "telephone": "(0755)28852881", "detail": 1, "uid": "7ee3ccf7b8aed470047ce87c"}, {"name": "富民铁路市场", "location": {"lat": 22.617064, "lng": 114.126306}, "address": "广东省深圳市龙岗区布李路164号", "province": "广东省", "city": "深圳市", "area": "龙岗区", "street_id": "96e3e1a27685cb82cae33c57", "detail": 1, "uid": "96e3e1a27685cb82cae33c57"}, {"name": "盐田海鲜批发市场", "location": {"lat": 22.590926, "lng": 114.284179}, "address": "深圳市盐田区海鲜街28", "province": "广东省", "city": "深圳市", "area": "盐田区", "street_id": "fc7675243816e6e34f776ea2", "telephone": "(0755)25202868", "detail": 1, "uid": "fc7675243816e6e34f776ea2"}]

返回20条
page_size最大为20
page_num参数可以控制页码数
下面是重点!


但是通过行政区地点检索 最多返回400个这是百度的限制
这时就需要 通过矩形区域检索
将深圳划分为多个区域进行检索
a和b的坐标在这里定位坐标拾取网站

import requests
import time
import json
keyword = "菜市场"
city = "深圳"

url = "http://api.map.baidu.com/place/v2/search"
a = "22.4717881915,113.7808575851"
b = "22.7960248910,114.3961567319"
#a为深圳左下角坐标,b为深圳右上角坐标

left_bottom = [113.7808575851,22.4717881915] # 设置区域左下角坐标(百度坐标系)
right_top = [114.3961567319,22.7960248910] # 设置区域右上角坐标(百度坐标系)

part_n = 5 # 设置区域网格(5*5)

x_item = (right_top[0]-left_bottom[0])/part_n
y_item = (right_top[1]-left_bottom[1])/part_n
n = 0 # 切片计数器
url0 = "http://api.map.baidu.com/place/v2/search?"
data = []
for i in range(part_n):
     for j in range(part_n):
         left_bottom_part = [left_bottom[0]+i*x_item,left_bottom[1]+j*y_item]; # 切片的左下角坐标
         right_top_part = [right_top[0]+i*x_item,right_top[1]+j*y_item]; # 切片的右上角坐标
         for k in range(20):
             time.sleep(0.6)
             url = url0 + "query=" + "市场" + "&page_size=20&page_num=" + str(k) + "&scope=1&bounds=" + str(
                 left_bottom_part[1]) + "," + str(left_bottom_part[0]) + "," + str(right_top_part[1]) + "," + str(
                 right_top_part[0]) + "&output=json&ak=" + "你的ak"
             print(str(left_bottom_part[1]) + "," + str(left_bottom_part[0]))
             print(str(right_top_part[1]) + "," + str(right_top_part[0]))
             print("===================================================")
             response = requests.request("GET", url)
             response = response.json()
             print(response)
             r = response["results"]
             data.append(r)

这样就可以突破深圳区域400的限制了,可以分为1010更细化 1010共返回1200+结果

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/43907.html

相关文章

  • 百度地图的使用-定位—逆地理编码(即坐标转地址)

    摘要:先上效果定位拖动定位定位动画动画结束显示地址实现思路中心点不变,在百度地图图层上覆盖自定义的定位布局拖动地图时,隐藏地址显示,定位标示落下来后显示地址拿到百度地图的拖动监听拿到中心点经纬度,逆地理编码即坐标转地址具体实现布局在主界面布局上覆 先上效果: 定位+拖动定位 定位动画 动画结束显示地址 showImg(https://segmentfault.com/img/bVbcQ8...

    tylin 评论0 收藏0
  • 从地址字符串获取省市区信息

    摘要:需求从手工填写的地址中,解析出省市区信息方法使用百度地图正逆地理编码虽然百度地图提供地点检索,但是是需要传入行政区信息的根据正地理编码服务接口将地址转换为经纬度,然后根据经纬度调用逆地理编码服务接口,得到结构化的行政区信息代码你的百度地图返 需求: 从手工填写的地址中,解析出省市区信息 方法 使用百度地图api正/逆地理编码PS: 虽然百度地图提供地点检索,但是是需要传入行政区信息的 ...

    MartinHan 评论0 收藏0
  • vue异步加载高德地图

    摘要:异步加载异步加载指的是为指定加载的回调函数,在的主体资源加载完毕之后,将自动调用该回调函数。 几种加载js的方式 同步加载 异步加载 延迟加载 同步加载 用的最多的一种方式,又称阻塞模式,会阻止浏览器的后续处理,停止后续的解析,只有当当前加载完成,才能进行下一步操作。所以默认同步执行才是安全的。但这样如果js中有输出document内容、修改dom、重定向等行为,就会造成页面堵塞。...

    zacklee 评论0 收藏0

发表评论

0条评论

SKYZACK

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<