这把我逼疯了。 到目前为止,我已经删除了这把钥匙1000次。 昨天很有魅力,今天不再 下面是python代码:
from googlemaps import GoogleMaps
gmaps = GoogleMaps("AIzaSyBIdSyB_td3PE-ur-ISjwFUtBf2O0Uo0Jo")
exactaddress ="1 Toronto Street Toronto"
lat, lng = gmaps.address_to_latlng(exactaddress)
print lat, lng
GoogleMapsError: Error 610: G_GEO_BAD_KEY
由于没有明显的原因,它现在返回上述错误。 我想我还没有达到要求的上限 为了安全起见,我甚至引入了延迟(1秒)…仍然会出现同样的错误
有人知道我怎么解决这个问题吗? 如果您可以指出一个替代我当前使用的python模块,那么使用不同的python模块就可以了。
谢谢 C类
PS:这个密钥是有效的,它是一个客户端密钥,当我在应用控制台中启用GoogleMapAPI3时,它被自动启用。对域或IP没有限制
编辑:以下是我最终使用的
def decodeAddressToCoordinates( address ):
urlParams = {
'address': address,
'sensor': 'false',
}
url = 'http://maps.google.com/maps/api/geocode/json?' + urllib.urlencode( urlParams )
response = urllib2.urlopen( url )
responseBody = response.read()
body = StringIO.StringIO( responseBody )
result = json.load( body )
if 'status' not in result or result['status'] != 'OK':
return None
else:
return {
'lat': result['results'][0]['geometry']['location']['lat'],
'lng': result['results'][0]['geometry']['location']['lng']
}
Jason给我指出的库也很有趣,但是由于我的代码是为了修复某些东西(一次性使用),所以我没有尝试他的解决方案。如果我能再写一次代码,我一定会考虑的:-)
自2013年9月起,googlemapsapiv2no longer works。下面是API v3的代码(基于this answer):
有关参数和其他信息的完整列表,请参见official documentation。
做了一些代码高尔夫,最终得到了这个版本。根据需要,您可能需要区分更多的错误条件。
相关问题 更多 >
编程相关推荐