使用Python GAE进行Google Maps Business Geocoding

时间:2022-02-21 23:12:20

In the Google API Console, the API Access generates keys for server, browser, Android, and iOS.

在Google API控制台中,API Access会为服务器,浏览器,Android和iOS生成密钥。

  1. Which type of api_key do I need to generate geocoding from Google App Engine Python?
  2. 我需要哪种类型的api_key才能从Google App Engine Python生成地理编码?

  3. If the answer is the server, do I need to find out the server's IP address for GAE, what are they? I got 74.125.129.141, which can probably change. (or would it?)
  4. 如果答案是服务器,我是否需要找出GAE的服务器IP地址,它们是什么?我得到了74.125.129.141,这可能会改变。 (或者会吗?)

  5. Can you help me find an example to generate the code if you have a Python GAE server I'm not sure if I'm doing the right thing?
  6. 如果你有一个Python GAE服务器,你能帮我找一个生成代码的例子吗?我不确定我是不是做对了?

I have this code, which displays the data from the result.content. My purpose is to save the geocode to the database using ndb.GeoPt(lat,lng):

我有这个代码,它显示result.content中的数据。我的目的是使用ndb.GeoPt(lat,lng)将地理编码保存到数据库:

def get_geo(address):
  browser_key = "browser_key"
  server_key = "server_key"
  address = cgi.escape(address.replace(" ","+"))
  sensor = "true"
  url = "http://maps.googleapis.com/maps/api/geocode/json?key="+ server_key +"&address=" + address + "&sensor="+ sensor
  result = urlfetch.fetch(url)
  data = json.loads(result.content) # This is the error
  geo = data
  #lat = data['results'][0]['geometry']['location']['lat']
  #long = data['results'][0]['geometry']['location']['lng']
  #return ndb.GeoPt(str(lat) +","+ str(long))
  return geo

I have this error in using the above example:

我在使用上面的例子时遇到此错误:

  File "C:\xampp\htdocs\mapjobs\main.py", line 18, in get_geo
    data = json.loads(result.content)
  File "C:\Python27\lib\json\__init__.py", line 310, in loads
    return _default_decoder.decode(s)
  File "C:\Python27\lib\json\decoder.py", line 346, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python27\lib\json\decoder.py", line 364, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

1 个解决方案

#1


0  

It should include the browser_key, and the url should be:

它应该包含browser_key,并且url应该是:

url = "http://maps.googleapis.com/maps/api/geocode/json?key="+ browser_key +"&address=" + address + "&sensor="+ sensor

#1


0  

It should include the browser_key, and the url should be:

它应该包含browser_key,并且url应该是:

url = "http://maps.googleapis.com/maps/api/geocode/json?key="+ browser_key +"&address=" + address + "&sensor="+ sensor