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]
评论列表
文章目录