我正在使用Python在Google App Engine上编写网站,并且我有一个位置数据存储区实体,该实体具有包含GPS坐标的字符串属性。我想让用户通过GPS坐标搜索,并且我想返回纬度或经度+/- 10点内的所有位置。基本上我想要做的是在下面的代码,但我不能这样排序GPS,一个因为它是一个字符串和两个,因为它是相同的属性。通过GPS位置对数据库查询进行排序
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)"
你能想到的任何方式基本上是这样做,而不必更改数据存储区设置的方式吗?有没有什么方法可以在不为Latitude和Longitude创建两个属性的情况下获取这些信息?
好,唯一的问题是,我不能比较纬度和长(这是浮动)数据库实体的GPSlocation(因为它是一个字符串),这就是我想要的 – clifgray