我正在构建一个应用程序,用户可以在其中搜索附近的位置。为此,我在我的views.py:
latitude = 23.734413
longitude = 90.4082535
user_location = Point(longitude, latitude, srid=4326)
class NearbyServices(generic.ListView):
model = Service
context_object_name = 'services'
queryset = Service.objects.annotate(distance=Distance('location', user_location)).order_by('distance')[0:6]
template_name = 'services/nearby.html'
我目前正在使用硬编码的用户位置,但我想让用户通过首先使用 HTML5 GeoLocation API 获取他们的位置来找到附近的位置。任何有关如何将其位置从前端获取到 listview 功能的帮助都会非常有帮助!
弑天下
相关分类