Utils.py 文件源码

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

项目:PokeAlarm 作者: PokeAlarm 项目源码 文件源码
def get_earth_dist(pt_a, pt_b=None):
    if type(pt_a) is str or pt_b is None:
        return 'unkn'  # No location set
    log.debug("Calculating distance from {} to {}".format(pt_a, pt_b))
    lat_a = radians(pt_a[0])
    lng_a = radians(pt_a[1])
    lat_b = radians(pt_b[0])
    lng_b = radians(pt_b[1])
    lat_delta = lat_b - lat_a
    lng_delta = lng_b - lng_a
    a = sin(lat_delta / 2) ** 2 + cos(lat_a) * cos(lat_b) * sin(lng_delta / 2) ** 2
    c = 2 * atan2(sqrt(a), sqrt(1 - a))
    radius = 6373000  # radius of earth in meters
    if config['UNITS'] == 'imperial':
        radius = 6975175  # radius of earth in yards
    dist = c * radius
    return dist


# Return the time as a string in different formats
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号