地理空间&谷歌appengine python中的基于位置的搜索 [英] geoSpatial & Location based search in google appengine python

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

问题描述

我想要实现诸如在airbnb上的地图拖动搜索之类的功能( https://www.airbnb.com/s/Paris--France?source=ds&page=1&s_tag=PNoY_mlz&allow_override%5B%5D=



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

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

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

$ $ p $ code $ def $(自己)

这是一个ajax函数,它获取地名,north_east和south_west
坐标,然后获取匹配搜索条件的结果,
创建一个结果列表。返回结果为json格式
: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)
为分行:
如果row.lon> north_east_longitude和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 = True)
lon = ndb.FloatProperty(required = True)
geoLocation = ndb.GeoPtProperty()

我想改进查询。


$ b

不,你不能通过检查查询中的所有4个条件来改进解决方案,因为ndb查询不支持multi ple属性。从 NDB查询(强调我的):


限制:数据存储强制对查询进行一些限制。
违反这些规定会导致异常。例如,
组合了太多的过滤器,使用多个
属性的不等式
,或者将一个不等式与
不同属性上的排序顺序组合在一起,目前都不允许使用。同时过滤
引用多个属性有时需要配置二级索引到



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


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

My model class is given below

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

I want to improve the query.

Thanks in advance.

解决方案

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

Limitations: The Datastore enforces some restrictions on queries. Violating these will cause it to raise exceptions. For example, combining too many filters, using inequalities for multiple properties, or combining an inequality with a sort order on a different property are all currently disallowed. Also filters referencing multiple properties sometimes require secondary indexes to be configured.

and

Note: As mentioned earlier, the Datastore rejects queries using inequality filtering on more than one property.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆