Python googlemaps.exceptions.HTTPError:HTTP错误:400
我用python编写了这段代码Python googlemaps.exceptions.HTTPError:HTTP错误:400,python,python-3.x,rest,google-maps,reverse-geocoding,Python,Python 3.x,Rest,Google Maps,Reverse Geocoding,我用python编写了这段代码 from googlemaps import Client apiKey = 'xxxx' lat = input("Please enter latitude: ") lng = input("Please enter longitude: ") maps = Client(apiKey) reverseGeo = maps.reverse_geocode(lat,lng) address = reverseGeo['Placemark'][0]['addres
from googlemaps import Client
apiKey = 'xxxx'
lat = input("Please enter latitude: ")
lng = input("Please enter longitude: ")
maps = Client(apiKey)
reverseGeo = maps.reverse_geocode(lat,lng)
address = reverseGeo['Placemark'][0]['address']
print(address)
每当我尝试运行并输入lat和lng值时,就会发生以下错误:
Please enter latitude: 5
Please enter longitude: 10
Traceback (most recent call last):
File "D:/Programs/github/mobile_application_development/Ex 1/part 1/main.py", line 6, in <module>
reverseGeo = maps.reverse_geocode(lat,lng)
File "C:\Users\Truong Dang\AppData\Roaming\Python\Python34\site-packages\googlemaps\client.py", line 356, in wrapper
result = func(*args, **kwargs)
File "C:\Users\Truong Dang\AppData\Roaming\Python\Python34\site-packages\googlemaps\geocoding.py", line 109, in reverse_geocode
return client._request("/maps/api/geocode/json", params)["results"]
File "C:\Users\Truong Dang\AppData\Roaming\Python\Python34\site-packages\googlemaps\client.py", line 253, in _request
result = self._get_body(response)
File "C:\Users\Truong Dang\AppData\Roaming\Python\Python34\site-packages\googlemaps\client.py", line 267, in _get_body
raise googlemaps.exceptions.HTTPError(response.status_code)
googlemaps.exceptions.HTTPError: HTTP Error: 400
请输入纬度:5
请输入经度:10
回溯(最近一次呼叫最后一次):
文件“D:/Programs/github/mobile\u application\u development/ex1/part 1/main.py”,第6行,在
reverseGeo=地图。反向地理代码(lat,lng)
文件“C:\Users\trung Dang\AppData\Roaming\Python34\site packages\googlemaps\client.py”,第356行,在包装器中
结果=函数(*args,**kwargs)
文件“C:\Users\Truong Dang\AppData\Roaming\Python\Python34\site packages\googlemaps\geocoding.py”,第109行,与地理编码相反
返回客户端。_请求(“/maps/api/geocode/json”,参数)[“结果”]
文件“C:\Users\Truong Dang\AppData\Roaming\Python\Python34\site packages\googlemaps\client.py”,第253行,在请求中
结果=自我获得身体(响应)
文件“C:\Users\Truong Dang\AppData\Roaming\Python\Python34\site packages\googlemaps\client.py”,第267行,在\u get\u正文中
引发googlemaps.exceptions.HTTPError(response.status\u代码)
googlemaps.exceptions.HTTPError:HTTP错误:400
我可以问一个原因以及如何修复它吗?查看代码,我认为您需要以以下形式之一将纬度经度作为单个参数传递:
地图。反向地理编码([lat,lng])
map.reverse_地理编码(lat+,'+lng)
映射。反向地理编码((lat,lng))
基本上,反向地理编码的第一个参数是在哪里可以看到支持哪些表示法谢谢,这绝对是问题所在!