e-picsa / picsa-apps

Monorepo for building tools to support E-PICSA Apps
https://picsa.app
GNU General Public License v3.0
5 stars 1 forks source link

feat(climate-tool): nearest station select #276

Open chrismclarke opened 1 month ago

chrismclarke commented 1 month ago

Is your feature request related to a problem? Please describe. We are expecting to add a large number of additional stations to the E-PICSA app, and as such selecting the correct station for a user may be difficult. It would be better if the app can automatically recommend which station to use, selecting the station that is closest to the user

Describe the solution you'd like When loading the climate too site-select page the app should request the user's approximate location, and use that to calculate which site is closest. This should then automatically pick that station (but still give the user the option to select a different one)

picsa app_climate(PICSA) (1)

Additional context See capacitor documentation for implementing Geolocation API

There are many ways to compute distance between 2 points (e.g. user current location and each station to determine what is closest). The simplest method would be to take the difference in coordinate values to calc longitdue and latitude differences (delta-x and delta-y), and use as 2 sides of a right-angled triangle to calculate the hypotenuse.

image

This won't be entirely accurate due to curvature of the earth, but should be a reasonable estimation. Alternatively could look at exact distances using functions built into leafletJS (e.g. https://leafletjs.com/reference.html#map-distance), or search online for formula (e.g. https://stackoverflow.com/a/51819649). These will be more computationally expensive so probably best to work out simple distances first.