我正在使用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