Search code examples
google-app-enginetwitter-bootstrap-3geolocationwebapp2geopoints

How to construct and store the geopoint


Am working on GAE with python. How to construct and store the latitude and longitude using GeoPoint?

This is my DB

class Customer(db.Model):
    name = db.StringProperty()
    address= db.PostalAddressProperty()
    geopoint= db.GeoPtProperty()

My code

class AddCustomerHandler(BaseHandler):
    input_fullname=self.request.get('fullname')
    input_cusaddress=self.request.get('cusaddress')
    input_latitude=self.request.get('latitude')
    input_longitude=self.request.get('longitude')


    input_geopoint= GeoPoint(input_latitude, input_longitude)
    logging.info('****************** xxxx= %s', input_geopoint)

    newcustomer=Customer(name=input_fullname,address=input_cusaddress,geopoint=input_geopoint)
    newcustomer.put()

Am trying this code. But Am getting error. How to store this geopoint field?


Solution

  • input_geopoint= GeoPoint(input_latitude, input_longitude) NameError: global name 'GeoPoint' is not defined.
    

    Am getting this error

    You're getting that error because you don't have the module imported where GeoPoint is defined.

    Add this import

    from google.appengine.api import search
    

    and then use like this

    input_geopoint = search.GeoPoint(input_latitude, input_longitude)
    

    Also see the docs