Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python googlemaps.exceptions.HTTPError:HTTP错误:400_Python_Python 3.x_Rest_Google Maps_Reverse Geocoding - Fatal编程技术网

Python googlemaps.exceptions.HTTPError:HTTP错误:400

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

我用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]['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))

  • 基本上,反向地理编码的第一个参数是在哪里可以看到支持哪些表示法

    谢谢,这绝对是问题所在!