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