Python 百度地图 API获取地点经纬度

from urllib import request
from urllib.parse import quote
import json
import string


def getLocation(address='address'):
 #  2OglfBzxobbyRn4S4bm9RByLManYHN是自己申请的key
    url="http://api.map.baidu.com/geocoder?output=json&key=2OglfBzxobbyRn4S4bm9RByLManYHN&city=&address="+address
    url = quote(url, safe=string.printable)
    req = request.urlopen(url)
    res = req.read().decode('utf-8','ignore').replace(u'\xa9', u'')
    result = json.loads(res)
    print(result)
#
#
if __name__ == '__main__':
    getLocation(address="西湖")

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_41884808/article/details/116505636