def get_distance(self, obj):

        curr_loc_str = self.context["request"].QUERY_PARAMS.get("curr_loc", None)
        curr_loc_lst = parse_float_list(curr_loc_str)

        if len(curr_loc_lst) == 2:
            geod = pyproj.Geod(ellps='WGS84')
            angle1,angle2,distance = geod.inv(curr_loc_lst[0], curr_loc_lst[1], obj.location.x[0], obj.location.y[0])
            return distance/METERS_PER_MILE

        return None
    def filter_queryset(self, request, queryset, view):
        """
        Limit queryset to all spots within user specified radius (in miles)
        from curr_loc.
        """

        radius = parse_int(request.query_params.get("radius", None))
        curr_loc = parse_float_list(request.query_params.get("curr_loc", None))

        if radius and len(curr_loc) == 2:
            return queryset.filter(location__distance_lte=(Point( curr_loc[0], curr_loc[1]), D(mi=radius)))
        return queryset
    def filter_queryset(self, request, queryset, view):
        """
        Limit queryset to all spots within user specified radius (in miles)
        from curr_loc.
        """

        radius = parse_int(request.query_params.get("radius", None))
        curr_loc = parse_float_list(request.query_params.get("curr_loc", None))

        if radius and len(curr_loc) == 2:
            return queryset.filter(
                location__distance_lte=(Point(curr_loc[0], curr_loc[1]),
                                        D(mi=radius)))
        return queryset
Esempio n. 4
0
    def get_distance(self, obj):

        curr_loc_str = self.context["request"].QUERY_PARAMS.get(
            "curr_loc", None)
        curr_loc_lst = parse_float_list(curr_loc_str)

        if len(curr_loc_lst) == 2:
            geod = pyproj.Geod(ellps='WGS84')
            angle1, angle2, distance = geod.inv(curr_loc_lst[0],
                                                curr_loc_lst[1],
                                                obj.location.x[0],
                                                obj.location.y[0])
            return distance / METERS_PER_MILE

        return None