使用地图API获取某地周边poi坐标

测试了百度地图和腾讯地图的api。百度地图没有开放周边地图的web调用接口。所以最后只能用腾讯地图api实现。
参考代码如下

# -*- coding: utf-8 -*-
"""
File Name:     gaode_ditu
Description :
Author :       meng_zhihao
mail :       312141830@qq.com
date:          2019/12/10
"""
import requests
import json
from urllib.parse import quote, unquote
import csv
import time

api_key = 'xxxxxx' # 高德地图key


def search_place(keyword): # 后续为了更精确建议设置城市
    url = 'https://restapi.amap.com/v3/place/text?'
    parameters = ''
    parameters+='key=%s'%api_key
    # parameters+='&types=010000|020000|030000|040000|050000|120000|150000'
    parameters+='&keywords=%s'%quote(keyword)

    url = url+parameters

    rsp = requests.get(url,timeout=20).text
    places = json.loads(rsp)
    print(places)
    firstplace = places['pois']
    if firstplace:
        firstplace = firstplace[0]
    else:
        firstplace = {}
    return firstplace

def nearby_search(location):

    data_set = []
    for page in range(1,11,1):
        time.sleep(0.2)
        url = 'https://restapi.amap.com/v3/place/around?'
        parameters = ''
        parameters+='key=%s'%api_key
        # parameters+='&types=010000|020000|030000|040000|050000|120000|150000'
        parameters+='&location=%s'%location
        parameters+='&page=%s'%page
        parameters+='&offset=%s'%25

        url = url+parameters
        print(url)
        rsp = requests.get(url,timeout=20).text
        places = json.loads(rsp)
        max_page = int(places['count'])/25+1
        data_set.extend(places['pois'])
        if page>=max_page:
            break
    return data_set


if __name__ == '__main__':
    while True:
        print('输入地名')
        keyword = input()
        place = search_place(keyword)
        print(place)
        location = place['location']
        pois = nearby_search(location)
        with open('pois.csv','a',encoding='utf_8_sig',newline='',) as fout:
            writer = csv.writer(fout)
            for poi in pois:
                data = [poi.get('name'),poi.get('type'),poi.get('address'),poi.get('location')]
                writer.writerow(data)
                fout.flush()
            print('插入完毕,数量 %s'%len(pois))


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值