On June 28, 2012, Google integrated the GeoPoint class into the Google App Engine Search API library with the specific intention of making spatial points searchable.
GeoPoints are stored as GeoFields in a search document. Google provides this support documentation that describes how to use GeoPoint with the search API.
The following example declares a GeoPoint and assigns it a GeoField in a search document. These new classes provide much more functionality than the ones listed below, but this code is the starting point for a basic understanding of how to use the new spatial search functions.
Building a document with the appropriate GeoPoint
#
GeoPoint document field search (slightly modified from search API documents)
## IMPORTS ## from google.appengine.api import search ndx = search.Index(DOCUMENT_INDEX) loc = (-33.857, 151.215) query = "distance(location, geopoint(-33.857, 151.215)) < 4500" loc_expr = "distance(location, geopoint(-33.857, 151.215))" sortexpr = search.SortExpression( expression=loc_expr, direction=search.SortExpression.ASCENDING, default_value=4501) search_query = search.Query( query_string=query, options=search.QueryOptions( sort_options=search.SortOptions(expressions=[sortexpr]))) results = index.search(search_query)
source share