如果用Mapbox绘图肯定就要用到,在Mapbox坐标系下,各个地点对应的地点经纬度,下面的方法可以达到这种目的,仅供大家参考!!!
import requests
import json
def getlongitudeAndLatitudeByMapBox(address, ak):
base_url = r'https://api.mapbox.com/geocoding/v5/mapbox.places/'
# 拼接字符串
base_url = f"{base_url}{address}.json?fuzzyMatch=false&language=zh_Hans&limit=1&access_token={ak}"
# 请求url地址
response = requests.get(base_url)
# 获取地址
loc: str = response.text
# # 转化为dict
loc = json.loads(loc)
center = loc['features'][0]['center']
name = loc['features'][0]['place_name_zh_Hans']
return center, name
if __name__ == "__main__":
list = ['成都市', '绵阳市', '鄱阳县', '青岛市', '西藏']
for l in list:
center, name = getlongitudeAndLatitudeByMapBox(l,
'pk.eyJ1Ijoid2pzMjIyIiwiYSI6ImNreGVkYnBlbDBtMnoyb3BlM2Jib3dxcDAifQ.GKErleh4uNcXyGpxdQa-og')
print(f"城市名:{name}------坐标:{center}")