1๐
โ
Iโm using a very similar setup (Django 1.5.4, Haystack 2.0.0, Elasticsearch 0.90.0) and this is what Iโve got:
from haystack.utils.geo import D, Point
from haystack.views import SearchView
class MySearchView(SearchView):
results = super(MySearchView, self).get_results()
...
lng = -112.0739
lat = 33.4492
center = Point(lng, lat)
radius = D(mi=50)
results = results.dwithin('geo_point', center, radius)
...
return results
An important thing to keep in mind as well is the backend. According to the Haystack backend support matrix (http://django-haystack.readthedocs.org/en/latest/backend_support.html#backend-support-matrix) only Solr and Elasticsearch support spatial data.
๐คJoey Wilhelm
Source:stackexchange.com