【问题标题】:Working with Google Maps API in Python在 Python 中使用 Google Maps API
【发布时间】:2014-10-03 14:41:32
【问题描述】:

我一直在尝试使用 google maps api,但我不断收到此错误:

"HTTPError: HTTP Error 403:Forbidden."

以这个简单的案例为例(它基于一个更复杂的案例,我从 XML 中提取地址):

from googlemaps import GoogleMaps
import xml.etree.ElementTree as et
gmaps = GoogleMaps()
pars = et.XMLParser(encoding='utf-8')
tree = et.parse('data.xml',parser=pars)
root = tree.getroot()
adress = "ringelblum 7 beer sheva"
lat , lng = gmaps.address_to_latlng(adress)
print lat, lng 

我看过不同的视频和教程,应该很简单。为什么它不起作用? 非常感谢各位。

【问题讨论】:

  • these results help中的任何一个?
  • 看起来很有趣,我看看然后回你。坦克很多!

标签: python google-maps google-maps-api-3 geolocation


【解决方案1】:

你可以试试这个,你需要有一个来自谷歌的密钥,请求库,并且知道你使用 json 的方式:

geo_s ='https://maps.googleapis.com/maps/api/geocode/json'

param = {'address': address, 'key': 'YOUR_KEY'}

response = requests.get(geo_s, params=param)

json_dict = response.json()

lat = json_dict['results'][0]['geometry']['location']['lat']
lng = json_dict['results'][0]['geometry']['location']['lng']

print({'lat': lat, 'lng': lng})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-15
    • 1970-01-01
    • 2015-05-27
    • 1970-01-01
    相关资源
    最近更新 更多