The trajectory was strange, so I changed to a better world map and use Mecator Projection instead
It is impossible to create a 100% precise 2D map . It will have some error regardless.
My convertion works well to about latitude between ±70°.
Convert geographic coordinates into pixel coordinates on my 2D map
- Get radians from degrees
longitude_rad = lon * math.pi / 180
latitude_rad = lat * math.pi / 180
- Get scale factor to fit my map size
x_scale = map_width / 2 / math.pi
y_scale = map_height / 2 / math.pi
The longitude scales ranges between ±
For the latitude part:
Theoretically, Mercator projection can range from
Numbers range around 3~4 can substitute pi for better fitting different latitude or maps. Here I use pi for general.
- Get x, y coordinates on 2D map using Mercator projection
x = map_width / 2 + x_scale * longitude_radians
y = map_height / 2 - y_scale * math.log((1 + math.sin(latitude_radians)) / (1 - math.sin(latitude_radians)))
map_width(map_height) / 2 centers the map around latitude/longitude = 0
In my source code are some commented-out lines. I tried to calculate the y coordinates by taking into account the distortion of the Mercator projection, instead of using a constant scale factor(
- MAP_Width: My preference is around 540
- MAP_Height:
int(ratio * MAP_Width * 0.4)
, you can change the number to anything you like - call_freq: by default the app will send request to the API endpoint every 10 seconds.
- history_queue_max_size: modify this to show longer/shorter trajectory (default 3 hrs).
- Create virtual env
>python -m venv env
- Get in the env
>.\env\Scripts\activate
- Install dependencies
>pip install -r requirements.txt
Steps 1 and 2 may vary on differnt OS