mod mooved gps functions from front end to back end
This commit is contained in:
parent
0066166765
commit
46b055c591
2 changed files with 30 additions and 29 deletions
27
backend/src/gps.py
Normal file
27
backend/src/gps.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import math
|
||||
|
||||
|
||||
class Coordinates:
|
||||
latitude: int
|
||||
longitude: int
|
||||
|
||||
|
||||
def distance_between_coords(lhs: Coordinates, rhs: Coordinates) -> float:
|
||||
R = 6371000 # Earth radius in meters
|
||||
|
||||
def to_rad(deg):
|
||||
return (deg * math.pi) / 180
|
||||
|
||||
d_lat = to_rad(rhs.latitude - lhs.latitude)
|
||||
d_lon = to_rad(rhs.longitude - lhs.longitude)
|
||||
|
||||
a = (d_lat / 2) ** 2 + (to_rad(lhs.latitude) * to_rad(rhs.latitude)) * (d_lon / 2) ** 2
|
||||
|
||||
c = 2 * (a**0.5) / ((1 - a) ** 0.5)
|
||||
|
||||
return R * c # distance in meters
|
||||
|
||||
|
||||
def is_within_range(my_coords: Coordinates, target_coords: Coordinates, max_range: float) -> bool:
|
||||
distance = distance_between_coords(my_coords, target_coords)
|
||||
return distance <= max_range
|
Loading…
Add table
Add a link
Reference in a new issue