pokeslack.py 文件源码

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

项目:PokemonGo-SlackBot 作者: rubenmak 项目源码 文件源码
def bearing_degrees(lat1, lon1, lat2, lon2):
    """
    Convert location in bearing degrees to be able to give a direction of where the Pokemon is located.
    :param lat1: user location latitude
    :param lon1: user location longitude
    :param lat2: pokemon location latitude
    :param lon2: pokemon location longitude
    :return: bearing degrees
    """

    # convert decimal degrees to radians
    lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
    # calculate the angle
    dlon = lon2 - lon1
    dlat = lat2 - lat1
    x = math.sin(dlon) * math.cos(lat2)
    y = math.cos(lat1) * math.sin(lat2) - (math.sin(lat1) * math.cos(lat2) * math.cos(dlon))
    initial_bearing = math.atan2(x, y)
    initial_bearing = math.degrees(initial_bearing)
    bearing = (initial_bearing + 360) % 360
    bearing = int(bearing)
    return bearing
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号