models.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:strans-pyra 作者: teresinahc 项目源码 文件源码
def nearest(cls, lat, long, **kwargs):
        """
        Search for the nearest stop from `lat` and `long`
        params.

        You should specify the stops to search, default is
        `Stop.all()`.

        @param lat: A float coercible value of latitude (eg.: -5.065533).
        @param long: A float coercible value of longitude (eg.: -42.065533).

        keywords params:
            stops:
                A list of `Stop` instance.
            route:
                A `Route` instance.

        @return: A tuple with a `Stop` object and a `Distance`
            object (see geopy.distance).
        """

        if kwargs.get('stops', False):
            stops = kwargs['stops']
        elif kwargs.get('route', False):
            stops = kwargs['route'].get_stops()
        else:
            stops = cls.all()

        dists = map(lambda stop: distance(
                (stop.lat, stop.long),
                (lat, long)
            ), stops)

        return min(zip(dists, stops))[::-1]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号