def get_dist_to_center(self):
"""
:return: The distance in meters between the last known position and the position represented by the middle
of the screen. If no distance can be calculated, it returns -1.
"""
if self.map is None:
return -1
try:
merc_x, merc_y = self.map.map_coord_to_map_projection(*self.to_local(Window.size[0]/2, Window.size[1]/2))
except ZeroDivisionError:
return -1
lat, lon = Map.to_geographic(merc_x, merc_y)
lat_last, lon_last = self.last_pos_wgs84
dist = Map.distance(lat_last, lon_last, lat, lon)
return dist
评论列表
文章目录