I am writing a website on Google App Engine in Python and I have a Location datastore entity that has a string property containing GPS coordinates. I want to let the user search by GPS coordinates and I want to return all locations that at within +/- 10 points of Latitude or Longitude. Basically what I wanted to do is in the following code but I cannot sort the GPS that way, one because it is a string and two because it is the same property.
inputlocation = self.request.get("userlocation")
g = geocoders.Google()
try:
place, (lat, lng) = g.geocode(inputlocation)
except ValueError:
geocodespot = g.geocode(inputlocation, exactly_one=False)
place, (lat, lng) = geocodespot[0]
GPSlocation = "("+str(lat)+", "+str(lng)+")"
GPSlocation = float(GPSlocation)
bound = 10
upper = GPSlocation + bound
lower = GPSlocation - bound
left = GPSlocation + bound
right = GPSlocation - bound
if GPSlocation:
locations = db.GqlQuery("select * from Location where GPSlocation>:1 and where GPSlocation>:2 and where GPSlocation <:3 and where GPSlocation <:4 order by created desc limit 20", upper, lower, left, right)
#example GPSlocation in the datastore = "(37.7699298, -93.4469157)"
Can you think of any way to do basically this without having to change the way my datastore is set up? Is there any way to get that information without just making two properties one for Latitude and one for Longitude?
It looks like Google GAE has a few tools for doing what you want to do:
the proximity_fetch looks like what you need