【问题标题】:googlemaps.exceptions.HTTPError: HTTP Error: 400googlemaps.exceptions.HTTPError:HTTP 错误:400
【发布时间】:2018-03-12 05:56:04
【问题描述】:

我在 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

我可以问一个原因以及如何解决它吗?

【问题讨论】:

    标签: python python-3.x rest google-maps reverse-geocoding


    【解决方案1】:

    查看代码,我认为您需要以下列形式之一将 Latidude 经度作为单个参数传递:

    1. 列表maps.reverse_geocode([lat, lng])
    2. 逗号分隔的字符串:maps.reverse_geocode(lat + ',' + lng)
    3. 一个元组maps.reverse_geocode((lat, lng))

    reverse_geocode 的第一个参数基本上是给normalize_lat_lng,在那里你可以看到支持的表示形式

    【讨论】:

    • 谢谢,肯定是这个问题!
    猜你喜欢
    • 2016-03-24
    • 2017-08-04
    • 2015-01-28
    • 1970-01-01
    • 1970-01-01
    • 2017-07-21
    • 1970-01-01
    • 2019-11-05
    • 2018-06-22
    相关资源
    最近更新 更多