python - Google Maps API -地址到坐标(纬度,经度)

标签 python google-maps google-geocoding-api

这让我发疯。 到目前为止,我已经删除了这个 key 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 模块是可以的。

谢谢 C

PS: key 有效,它是一个客户端 key ,当我在应用程序控制台中启用 GoogleMAP API3 时,它会自动启用。对域或 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 向我指出的库也很有趣,但由于我的代码旨在修复某些问题(一次性使用),所以我没有尝试过他的解决方案。如果我再次编写代码,我肯定会考虑 :-)

最佳答案

尽管 Google 不赞成使用 googlemaps 进行 V2 调用(这就是您看到调用中断的原因),但他们最近宣布他们为开发人员提供六个月的延期(至 2013 年 9 月 8 日)以从 V2 迁移到 V3 API。参见 Update on Geocoding API V2了解详情。

与此同时,查看 pygeocoder作为可能的 Python V3 解决方案。

关于python - Google Maps API -地址到坐标(纬度,经度),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15285691/

相关文章:

php - 无法在“file_get_contents()”中加载cafile流?

google-maps - 谷歌地理编码中视口(viewport)和边界之间的区别

google-geocoding-api - 了解谷歌地理编码服务组件过滤器

python - python 中的矩阵问题

python - 艰难地学习 Python 帮助 : Exercise 13

swift - 如果表为空则显示 map

google-maps - 谷歌地图人口普查区

Python & lxml/xpath : Parsing XML

python - 删除除特定组合外的任何小写字符

android - "Method in type not applicable for arguments"错误