GeoDjango & SpatiaLite - filtering nearby objects

旧巷老猫 提交于 2019-12-01 21:37:58

Theory:

This is a pretty obscure error related to those two:

Since you are using geodetic coordinate systems (like the EPSG 4326) you need to provide the distance in degrees.

Here is a very good explanation on how to transform km to degrees accurately enough: How do I convert kilometres to degrees in Geodjango/GEOS?

Finally I would suggest to use the dwithin.


Praxis:

  • 1km ~= 0.008 deg
  • The query now should look:

    Business.gis.filter(location__dwithin=(request.user.location, 0.008))
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!