Python:调用百度地图和高德地图API获得信息检索结果

前言

不管是百度地图还是高德地图api,在个人开发者认证完成之前的每日调用配额低得可怜,认证通过后每日可以在信息检索上,每日上限是30万,并发量可以达到50,所以必须认证!

代码

import requests
import json
import openpyxl

def get_bd_address(keyword):
    '''通过百度地图api获得信息'''
    url = 'http://api.map.baidu.com/place/v2/search?query=' + keyword + '®ion=上海&output=json&ak=你的ak'
    answer = json.loads(requests.get(url).text)
    first_address = answer['results'][0]['address']
    first_address_area = answer['results'][0]['area']
    return first_address, first_address_area

def get_gd_address(keyword):
    '''通过高德地图api获得信息'''
    url = 'https://restapi.amap.com/v3/place/text?keywords=' + keyword + '&city=上海&offset=1&output=JSON&key=你的key'
    answer = json.loads(requests.get(url).text)
    first_address = answer['pois'][0]['address']
    first_address_area = answer['pois'][0]['adname']
    return first_address, first_address_area

print('高德地图获得的信息:', get_gd_address('上海信息大楼'))
print('百度地图获得的信息:', get_bd_address('上海信息大楼'))

你可能感兴趣的:(Python基础)