5

我的网站(在服务器端使用 python/django)接收 Latlng(Google Maps API 2)地理编码的用户输入,并将其存储到 Google Appengine Datastore 中/从中检索。

        c = myplace.MyPlace(
            geo_point = latlng,
        c.put()

其中 DB.Model 定义如下:

from google.appengine.ext import db

class Myplace(db.Model):
    geo_point   = db.GeoPtProperty()

问题是当我保存 any 时geocode(e.g. 8.928487062665504, 105.062255859375),检索到的总是37.4229181,-122.0854212,这是 Google 的山景城位置。在此过程中没有错误消息。

你能告诉我为什么会发生这种情况吗?


商店信息.py ...

def new(req):                       
   if req.method == 'POST':
        try:
            u_form = ShopInfoForm(req.POST)
            if not u_form.is_valid():
                return err_page('Invalid input values.')

            # geo_point
            latlng = None
            if req.POST.get('geo_point'):
                latlng = req.POST.get('geo_point').strip()
                latlng = string.replace(latlng, '(', '')
                latlng = string.replace(latlng, ')', '')

            c = myplace.MyPlace(owner = u,
                    nickname = u.nickname,
                    #title = unicode(req.POST['title'].strip(), 'utf8'),
                    #content = unicode(req.POST['content'].strip(), 'utf8'),
                    title = req.POST['title'].strip(),
                    content = req.POST['content'].strip(),
                    geo_point = latlng,
                    post_time = datetime.now())
            c.put()                  ##WRITE HERE

            return HttpResponseRedirect('/shop/'+str(c.key().id())+'/read/')
        except Exception, x:
            return err_page('Error.')
    return err_page('Wrong request')

def read(req, shop_id):         
    if req.method == 'GET':
        user_info = users.get_current_user()
        s = myplace.MyPlace.get_by_id(int(shop_id))  
        if not s:
            return err_page('Wrong request')

        context = {'static_path': STATIC_PATH,
                   'user_info': user_info,
                   'shop' : s}            ##READ HERE
        return render_to_response('shop_read.html', context)
    return err_page('Wrong request')

**shop_read.html**

    {% if shop.geo_point %}
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=" type="text/javascript"></script>
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">google.load("jquery", "1");</script>
<script type="text/javascript">
4

0 回答 0