python 利用高德地图定位小区名字

2020-11-26  本文已影响0人  程序里的小仙女

1.利用地址定位到小区名字

这里调研的是利用高德的poi检索
开发文档地址:
https://lbs.amap.com/api/webservice/guide/api/search
需要申请开放平台的账号,新建应用:


2.源码如下:

# -*- coding: utf-8 -*-
"""
 @Time   : 2020/11/26 9:20 
 @Athor   : LinXiao
 @功能   : 根据地址找到小区名字
"""
import os
import sys

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from pprint import pprint
import requests
import ast

from proxypool.ip_queue import ip_queue_redis

class GaoDe:
    def __init__(self):
        ip=ip_queue_redis()
        self.proxy={'https': ip}
        self.api_qianzui="http://restapi.amap.com/v3/place/text?key=57c6b6feeff34100a2c07f1e0cc1e650&keywords="
        self.api_houzui="&children=0&offset=1&page=1&extensions=base&types=住宅区"

    def param(self, address, city):
        url=self.api_qianzui + str(address) + str(f"&city={city}")
        print(url)
        return url

    def str_to_dict(self, data):
        new_dic=ast.literal_eval(str(data))
        return new_dic

    def get_gaode_api(self, url):
        res=requests.request("GET", url, timeout=30).text  # str
        res=self.str_to_dict(res)
        # pprint(res)
        return res

    def clean_data(self, url):
        data=self.get_gaode_api(url)
        name=data.get('pois')[0].get('name')
        print(name)
        return name


if __name__ == '__main__':
    gaode_map=GaoDe()
    # url ="http://restapi.amap.com/v3/place/text?key=57c6b6feeff34100a2c07f1e0cc1e650&keywords=成都市武侯区龙腾正街1号&types=住宅区&city=成都&children=0&offset=1&page=1&extensions=base"
# address="成都市武侯区龙腾正街1号"
    # address="茂业豪园"
    # address="新鸿南路86号"
    # address="成都市成华区圣灯路58号"
    # address="重庆市永川区凤凰大道66号"
    # address="重庆市荣昌区昌元街道棠香北街39号"
    # address="成都市武侯区机投镇皇家花园D15栋2层"
    # address="长沙市雨花区红旗区四片016栋103"
    # address="武汉市汉阳区二桥路19号"
    # address="西安市高新区电子西街2号紫薇馨苑26号"
    # address="重庆市北部新区金州大道66号"
    # address="位于广东省广州市天河区天源路挹翠北街9号"
    address="西安市雁塔区白沙路3号11幢21803号"

    city="成都"
    url=gaode_map.param(address, city)
    res=gaode_map.clean_data(url)

运行结果展示:


这里就完美的将地址和小区名称对应起来了!

请大家多多点赞,转载,支持,不足之处多多指教!

上一篇下一篇

猜你喜欢

热点阅读