22import base64
33import struct
44import config
5- import math
65from math import radians , cos , sin , asin , sqrt
76from geopy .distance import vincenty
87from geopy .geocoders import GoogleV3
1615def get_location_coords ():
1716 return (COORDS_LATITUDE , COORDS_LONGITUDE , COORDS_ALTITUDE )
1817
19- def get_lat ():
20- return COORDS_LATITUDE
21-
22- def get_lot ():
23- return COORDS_LONGITUDE
24-
25- def set_lat (new ):
26- global COORDS_LATITUDE
27- COORDS_LATITUDE = f2i (new )
28-
29- def set_lot (new ):
30- global COORDS_LONGITUDE
31- COORDS_LONGITUDE = f2i (new )
32-
3318def set_location (location_name ):
3419 geolocator = GoogleV3 ()
3520 loc = geolocator .geocode (location_name )
@@ -38,8 +23,7 @@ def set_location(location_name):
3823 set_location_coords (loc .latitude , loc .longitude , loc .altitude )
3924
4025def set_location_coords (lat , long , alt ):
41- if config .debug :
42- print ('[!] lat/long/alt: {} {} {}' .format (lat , long , alt ))
26+ print ('[!] lat/long/alt: {} {} {}' .format (lat , long , alt ))
4327 global COORDS_LATITUDE , COORDS_LONGITUDE , COORDS_ALTITUDE
4428 global FLOAT_LAT , FLOAT_LONG
4529 FLOAT_LAT = lat
@@ -69,86 +53,10 @@ def get_near(map):
6953 for block in cell .b :
7054 for obj in block .c :
7155 for stop in obj .s :
72- #if distance(stop.lat,stop.lon,COORDS_LATITUDE,COORDS_LONGITUDE):
73- ms .append ((stop .name ,stop .lat ,stop .lon ,get_distance (stop .lat ,stop .lon ,COORDS_LATITUDE ,COORDS_LONGITUDE )))
74- return ms
75-
76- def get_near_p (map ):
77- ms = []
78- for cell in [map ]:
79- for block in cell .b :
80- for obj in block .c :
81- for stop in obj .p :
82- #if distance(stop.lat,stop.lon,COORDS_LATITUDE,COORDS_LONGITUDE):
83- ms .append ((stop .t .type ,stop .lat ,stop .lon ,stop .name ,stop .hash ,get_distance (stop .lat ,stop .lon ,COORDS_LATITUDE ,COORDS_LONGITUDE )))
84- for stop in obj .s :
85- if stop .p .type :
86- ms .append ((stop .p .type ,stop .lat ,stop .lon ,stop .name ,stop .p .u2 ,get_distance (stop .lat ,stop .lon ,COORDS_LATITUDE ,COORDS_LONGITUDE )))
56+ if is_near (stop .lat ,stop .lon ,COORDS_LATITUDE ,COORDS_LONGITUDE ):
57+ ms .append ((stop .name ,stop .lat ,stop .lon ))
8758 return ms
8859
89- def move_to (lat1 , lot1 ,lat2 , lot2 ):
90- if (lat1 > lat2 ):
91- while (lat1 < lat2 ):
92- lat1 = lat1 - 0.000095
93- else :
94- while (lat1 < lat2 ):
95- lat1 = lat1 + 0.000095
96- if (lot1 > lot2 ):
97- while (lot1 > lot2 ):
98- lot1 = lot1 - 0.000095
99- else :
100- while (lot2 > lot1 ):
101- lot1 = lot1 + 0.000095
102- return lat1 , lot1 ,lat2 , lot2
103-
104- def distance (lat1 , lon1 ,lat2 , lon2 ):
105- lat1 = l2f (lat1 )
106- lon1 = l2f (lon1 )
107- lat2 = l2f (lat2 )
108- lon2 = l2f (lon2 )
109- radius = 6371 # km *1000 m
110- dlat = math .radians (lat2 - lat1 )
111- dlon = math .radians (lon2 - lon1 )
112- a = math .sin (dlat / 2 ) * math .sin (dlat / 2 ) + math .cos (math .radians (lat1 )) \
113- * math .cos (math .radians (lat2 )) * math .sin (dlon / 2 ) * math .sin (dlon / 2 )
114- c = 2 * math .atan2 (math .sqrt (a ), math .sqrt (1 - a ))
115- d = radius * c * 1000
116- return d < config .distance
117-
118- def get_distance (lat1 , lon1 ,lat2 , lon2 ):
119- lat1 = l2f (lat1 )
120- lon1 = l2f (lon1 )
121- lat2 = l2f (lat2 )
122- lon2 = l2f (lon2 )
123- radius = 6371 # km *1000 m
124- dlat = math .radians (lat2 - lat1 )
125- dlon = math .radians (lon2 - lon1 )
126- a = math .sin (dlat / 2 ) * math .sin (dlat / 2 ) + math .cos (math .radians (lat1 )) \
127- * math .cos (math .radians (lat2 )) * math .sin (dlon / 2 ) * math .sin (dlon / 2 )
128- c = 2 * math .atan2 (math .sqrt (a ), math .sqrt (1 - a ))
129- d = radius * c * 1000
130- return d
131-
132- def haversine (lon1 , lat1 , lon2 , lat2 ):
133- lat1 = l2f (lat1 )
134- lon1 = l2f (lon1 )
135- lat2 = l2f (lat2 )
136- lon2 = l2f (lon2 )
137- """
138- Calculate the great circle distance between two points
139- on the earth (specified in decimal degrees)
140- """
141- # convert decimal degrees to radians
142- lon1 , lat1 , lon2 , lat2 = map (radians , [lon1 , lat1 , lon2 , lat2 ])
143-
144- # haversine formula
145- dlon = lon2 - lon1
146- dlat = lat2 - lat1
147- a = sin (dlat / 2 )** 2 + cos (lat1 ) * cos (lat2 ) * sin (dlon / 2 )** 2
148- c = 2 * asin (sqrt (a ))
149- r = 6371 # Radius of earth in kilometers. Use 3956 for miles
150- return c * r * 1000
151-
15260def is_near (locx ,locy ,myx ,myy ):
15361 tmp1 = (l2f (locx ), l2f (locy ))
15462 tmp2 = (l2f (myx ), l2f (myy ))
0 commit comments