Python 中的 Google App Engine 和 Google Maps 邻近搜索
由于 GQL 引擎的限制,建议想要执行邻近搜索的人们应该使用建议的地理模型找到绕过这些限制的方法。这可能不是一个非常优雅或快速的解决方案,但有什么可以阻止任何人使用这里的算法:
SELECT id, ( 3959 * acos( cos( radians(lat_t) ) * cos( radians( lat ) ) * cos( 弧度( lng ) - 弧度(lng_t) ) + sin( 弧度(lat_t) ) * sin( 弧度( lat ) ) ) ) AS 距离 FROM 商店距离 << 25 ORDER BY distance
作为计算距离的简单方法。也就是说,我们只需循环遍历数据存储中的每条记录,手动计算每对 (lat, lng) 和 (lat_t, lng_t) 的距离,从而获得目标距离内所有记录的 id不求助于使用 HAVING 命令?总而言之,我们将执行一个简单的 GQL 查找来获取所有记录并循环遍历所有 lng/lat 对并与我们的目标值进行比较。
Due to the limitations of the GQL engine it has been suggested that people wanting to perform a proximity search should find someway around these limitations using the suggested geomodel. It might not be a very elegant or fast solution but is there anything to stop anyone using the algorithm from here:
SELECT id, ( 3959 * acos( cos( radians(lat_t) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(lng_t) )
+ sin( radians(lat_t) ) * sin( radians( lat ) ) ) ) AS distance
FROM Stores HAVING distance < 25
ORDER BY distance
as a simple way of computing the distance. I.e. we simply compute the distance by hand for each and every pair (lat, lng) and (lat_t, lng_t) by looping through each and every record in our datastore and thus getting the id that way of all records that are within our target distance without recourse to using the HAVING command? So to summarize we would do a simple GQL look up to get all records and loop through all pairs of lng/lat and compare with our target values.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然,该代码片段是 SQL 的某种风格,与数据存储区更简单的基于索引的查找不兼容。
如果你的意思是你只想获取所有实体并使用 python 在内存中执行距离计算;那么这当然是可能的,但您将仅限于在相对较小的一组实体上执行此操作或使用任务批量执行此操作。
看一下GeoModel,它是专为这个用例而设计的。
Obviously that snippet is some flavour of SQL and not compatible with the Datastore's much simpler index based lookup.
If you mean you want to just fetch ALL your entities and perform the distance calculations in memory with python; then that is certainly possible, but you will be limited to doing this on a relatively small set of Entities or doing it in batches using Tasks.
Take a look at GeoModel which is designed for this very use case.