App Engine数据存储区不会保存LatLng(Google地图)值

时间:2012-05-05 14:53:52

标签: python google-app-engine google-cloud-datastore geocode

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

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

其中DB.Model定义如下:

from google.appengine.ext import db

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

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

你能告诉我为什么会这样吗?


ShopInfo.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">

0 个答案:

没有答案