Google App Engine中Google地图不显示标记
我在Python中创建了一个Google App Engine项目,它在我的本地电脑上运行得很好,但当我把它上传到geo-event-maps.appspot.com时,标记却没有显示出来。
我有一个定时任务,它会调用/place这个地址。
我没有看到任何日志错误。
我的数据存储是空的!
我上传的文本文件是这样的:
file_path = os.path.dirname(__file__)
path = os.path.join(file_path, 'storing', 'txtFiles')
有没有办法检查这些文件是否已经上传成功?
我现在完全不知道该怎么办。有没有人遇到过类似的问题?
下面是我的main.py文件:
'''
Created on Mar 30, 2011
@author: kimmasterson
'''
#!/usr/bin/env python
from google.appengine.ext import webapp
from google.appengine.ext import db
from placemaker import placemaker
import logging
import wsgiref.handlers
import os, glob
from google.appengine.dist import use_library
use_library('django', '1.2')
from google.appengine.ext.webapp import template
class Story(db.Model):
id = db.StringProperty()
loc_name = db.StringProperty()
title = db.StringProperty()
long = db.FloatProperty()
lat = db.FloatProperty()
link = db.StringProperty()
date = db.StringProperty()
class MyStories(webapp.RequestHandler):
def get(self):
temp = db.Query(Story)
temp = temp.count()
story_set = Story.all()
template_values = {
'storyTemp': story_set
}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
class place(webapp.RequestHandler):
def get(self):
#path = '/storing/txtFiles'
file_path = os.path.dirname(__file__)
path = os.path.join(file_path, 'storing', 'txtFiles')
try:
for infile in glob.glob(os.path.join(path, '*.txt')):
#print infile
f = open(infile, 'r')
data = f.read()
newfile = infile.replace('.txt', '')
newfile = newfile.replace('/storing/txtFiles/', '')
#print newfile
storyname = 'http://www.independent.ie/national-news/' + newfile
#print storyname
#print newfile
#logging.info(data)
p = placemaker('HSnG9pPV34EUBcexz.tDYuSrZ8Hnp.LowswI7TxreF8sXrdpVyVIKB4uPGXBYOA9VjjF1Ca42ipd_KhdJsKYjI5cXRo0eJM-')
print p.find_places(data)
for place in p.places:
splitted = place.name.split()
for word in splitted:
temp = db.Query(Story)
temp = temp.filter("link = ", storyname)
results = temp.fetch(limit=1)
if len(results) > 0:
break
elif 'IE' in word:
print temp
print 'success'
print 'name of the file is:' + newfile
story = Story(name=newfile, long=place.centroid.longitude, lat=place.centroid.latitude, link=storyname, loc_name=place.name, title=newfile).put()
#logging.info(type(place.centroid.latitude))
except:
print 'error'
def main():
application = webapp.WSGIApplication([('/', MyStories), ('/place', place)],
debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()
这是我的cron.yaml文件:
cron:
- description: running place
url: /place
schedule: every day 11:05
app.yaml文件内容如下:
application: geo-event-maps
version: 2
runtime: python
api_version: 1
handlers:
- url: .*
script: main.py
builtins:
- datastore_admin: on
2 个回答
1
首先,确保你是通过相对路径来访问你的文件。
接下来,确认你没有在app.yaml
文件中把这些文件标记为静态文件,因为静态文件不会和你的应用程序上传到同一个地方(它们会被发送到一个地方,让谷歌的前端服务器可以更直接地提供这些文件)。
2
你需要确保你的文件和应用程序代码一起上传,不能把它们标记为静态文件,否则你的代码就无法访问这些文件。运行 appcfg.py
时加上 --verbose
这个选项,确保它们被上传了。
第二个问题,在你的 place
类里,你把路径定义为 path = '/storing/txtFiles'
。这个是错的。你的路径可能应该是这样的:
file_path = os.path.dirname(__file__)
path = os.path.join(file_path, 'storing', 'txtFiles')
另外,我建议你不要使用 print
,而是用 self.response.out.write(stuff_to_write)
来输出内容。
你可能还想看看使用 key_names
。这样可以让你的代码更高效,因为你可以用批量的 db.get
来代替在嵌套的 for 循环里使用 db.Query
。使用 Appstats,尽量减少 RPC 的数量。