python - Google App Engine 中的 Google map 上未显示标记

标签 python google-app-engine google-maps cron google-maps-markers

我用 Python 创建了一个 Google App Engine 项目,它在我的本地主机上运行,​​但是当我将它上传到 geo-event-maps.appspot.com 时,标记没有显示。 我有一个 cron,它运行以调用/place。 我没有日志错误 我的数据存储是空的! 正在上传 txt 文件:

    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

最佳答案

您需要确保您的文件是通过您的应用程序代码上传的,它们不能被标记为静态文件,否​​则您的代码将无法访问它们。使用 --verbose 标志运行 appcfg.py 并确保它们已上传。

第二个问题,在您的 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。通过在嵌套的 for 循环中运行批处理 db.get 而不是 db.Query,您将能够使您的代码更加高效。使用 Appstats并尽量减少 RPC 的数量。

关于python - Google App Engine 中的 Google map 上未显示标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5702013/

相关文章:

python - 基于列名的 Pandas 数据框条件均值

python - 如何将源和目标参数定义为shortest_path的数组?

python - 当给出预计数时,计算大型文本文件中字符串的频率(有效)

python - 在 Google App Engine 上连接 python 后端和 vue.js 前端

python - Google App Engine 模型类是如何存储的?

python - eventlet.monkey_patch() 破坏了 docker 容器中的 ipdb

android - 谷歌云端点 : verifyToken: Signature length not correct

android - 如何使用谷歌地图V2通过触摸在 map fragment 上绘制形状

javascript - 谷歌地图设置中心。专注于新位置

Android 谷歌地图 API v2 : get my bearing location