我想实现类似于airbnb上的地图拖动搜索(override%5B%5D=)
我在数据存储中保存这样的数据
user.lat = float(lat)
user.lon = float(lon)
user.geoLocation = ndb.GeoPt(float(lat),float(lon))每当我拖放地图或放大或放大时,我就会在控制器中得到以下参数
def get(self):
"""
This is an ajax function. It gets the place name, north_east, and south_west
coordinates. Then it fetch the results matching the search criteria and
create a result list. After that it returns the result in json format.
:return: result
"""
self.response.headers['Content-type'] = 'application/json'
results = []
north_east_latitude = float(self.request.get('nelat'))
north_east_longitude = float(self.request.get('nelon'))
south_west_latitude = float(self.request.get('swlat'))
south_west_longitude = float(self.request.get('swlon'))
points = Points.query(Points.lat<north_east_latitude,Points.lat>south_west_latitude)
for row in points:
if row.lon > north_east_longitude and row.lon < south_west_longitude:
listingdic = {'name': row.name, 'desc': row.description, 'contact': row.contact, 'lat': row.lat, 'lon': row.lon}
results.append(listingdic)
self.write(json.dumps({'listings':results}))我的模型类如下所示
class Points(ndb.Model):
name = ndb.StringProperty(required=True)
description = ndb.StringProperty(required=True)
contact = ndb.StringProperty(required=True)
lat = ndb.FloatProperty(required=True)
lon = ndb.FloatProperty(required=True)
geoLocation = ndb.GeoPtProperty()我想改进查询.
提前谢谢。
发布于 2017-01-11 05:07:01
不,不能通过检查查询中的所有4个条件来改进解决方案,因为ndb查询不支持多个属性上的不平等筛选器。来自NDB查询 (重点雷):
限制:数据存储对查询执行一些限制。违反这些规则将导致出现异常。例如,组合过多的过滤器、为多个属性使用不等式的、或将一个不等式与不同属性上的排序顺序组合在一起,这些都是当前不允许的。此外,引用多个属性的筛选器有时需要配置辅助索引。
和
注意:如前所述,数据存储拒绝使用对多个属性进行不平等筛选的查询。
https://stackoverflow.com/questions/40550590
复制相似问题