import random
import json
from urllib.request import urlopen, quote
import requests
def bd_get_city(lng, lat):
lng = str(lng)
lat = str(lat)
url = 'https://api.map.baidu.com/reverse_geocoding/v3/'
output = 'json'
ak_list = ['A', 'B',
'C', '7IxGsTGoz5zF7hcBnaWl2jEdtLjE7V8R']
rand_index = random.randint(0,3)
cur_ak = ak_list[rand_index]
url = url + '?'+ 'ak=' + cur_ak + '&output=json&coordtype=wgs84ll&' + 'location=' + lat + ',' + lng
req = urlopen(url)
res = req.read().decode()
temp = json.loads(res)
province = temp['result']['addressComponent']['province']
city = temp['result']['addressComponent']['city']
return [province, city] # 纬度 latitude , 经度 longitude ,
bd_get_city(121.49884033194, 31.225696563611)
python,基于百度地图API获取某个经纬度对应的城市信息
最新推荐文章于 2023-03-14 16:32:30 发布