本文介绍了地理空间&google appengine python中基于位置的搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在airbnb(https://www.airbnb.com/s/Paris--France?source=ds&page=1&s_tag=PNoY_mlz&allow_override%5B%5D=)

I want to achieve something like the map drag search on airbnb (https://www.airbnb.com/s/Paris--France?source=ds&page=1&s_tag=PNoY_mlz&allow_override%5B%5D=)

我将这样的数据保存在数据存储区

I am saving the data like this in datastore

 user.lat = float(lat)
     user.lon = float(lon)
     user.geoLocation = ndb.GeoPt(float(lat),float(lon))

每当我拖动 &放下地图或放大或缩小我在控制器中获得以下参数

and whenever I drag & drop map or zoom in or zoom out I get following parameters in my controller

    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()

我想改进查询.

提前致谢.

推荐答案

否,您无法通过检查查询中的所有 4 个条件来改进解决方案,因为 ndb 查询不支持多个属性的不等式过滤器.来自 NDB 查询(重点是我的):

No, you cannot improve the solution by checking all 4 conditions in the query because ndb queries do not support inequality filters on multiple properties. From NDB Queries (emphasis mine):

限制:数据存储区对查询实施了一些限制.违反这些将导致它引发异常.例如,组合太多过滤器,对多个使用不等式属性,或将不等式与排序顺序组合在一起不同的财产目前都被禁止.还有过滤器引用多个属性有时需要二级索引进行配置.

注意:如前所述,数据存储区拒绝对多个属性使用不等式过滤的查询.

这篇关于地理空间&amp;google appengine python中基于位置的搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 11:41