5

My website (with python/django on the server side) receives user input of Latlng (Google Maps API 2) geocode and stores it into/ retrieves it from the Google Appengine Datastore.

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

where the DB.Model is defined as follows:

from google.appengine.ext import db

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

The problem is when I save any geocode(e.g. 8.928487062665504, 105.062255859375), what gets retrieved is always 37.4229181,-122.0854212, which is Google's Mountain View location. There is no error message during this process.

Can you tell me why this might happen?


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">
Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
Jason O.
  • 3,168
  • 6
  • 33
  • 72

0 Answers0