Python 谷歌方向API:不将地址翻译成英语
我正在尝试使用Google Direction API服务。我的地址是中文的,不是英文的。如果我直接在浏览器中输入URL,Google会返回中文地址。但是,如果我在Python程序中包含URL,Google将把中文地址翻译成英文 在下文中,变量Python 谷歌方向API:不将地址翻译成英语,python,google-directions-api,Python,Google Directions Api,我正在尝试使用Google Direction API服务。我的地址是中文的,不是英文的。如果我直接在浏览器中输入URL,Google会返回中文地址。但是,如果我在Python程序中包含URL,Google将把中文地址翻译成英文 在下文中,变量a、b、c和d是四个中文地址 from urllib.parse import quote from urllib.request import urlopen import json url = 'http://maps.googleapis.co
a
、b
、c
和d
是四个中文地址
from urllib.parse import quote
from urllib.request import urlopen
import json
url = 'http://maps.googleapis.com/maps/api/directions/json?'
a = '台中市霧峰區吉峰東路168號'
b = '桃園機場'
c = '台中市中區自由路一段1號'
d = '台中市大里區國光路一段1號'
url = (url +
'origin=' + quote(a) +
'&destination=' + quote(b) +
'&waypoints=optimize:true|' + quote(c) + '|' + quote(d) + '&sensor=false')
print(url)
direction = urlopen(url).read().decode('utf-8')
方向
中的地址都翻译成英文地址。如何防止Google翻译地址?您可以使用参数语言
看
req_url = ("{}origin={}&destination={}&waypoints=optimize:true|{}|{}"
"&sensor=false&language=zh-TW".format(
url, quote(a), quote(b), quote(c), quote(d)))
print(req_url)
direction = urlopen(req_url).read().decode('utf-8')
with open('result.txt', 'w') as ii:
ii.write(direction.encode('utf-8'))