You can use readings from your environment to calculate your height above sea level with a good degree of accuracy. The BME280 sensor can measure things like air pressure, humidity, and temperature and then relay that information to the Raspberry Pi Pico. From there, the code you have installed can take the air pressure reading, and use it to figure out your altitude.
The reason this works partially comes down to gravity. It affects everything with mass to some degree, and pulls most of earth’s gas as close to the surface as possible. This results in the air being dense at sea level, with the density decreasing the further up you go. The denser the air is, the more pressure it can exert, so the lower densities at higher up will result in less pressure exerted on the sensor.
Air pressure is around 14.7 PSI at sea level, and only about 4.84 PSI at the summit of Mount Everest. If you’re hiking, you’re on land and the pressure you’re experiencing will be somewhere in between. As a rule of thumb, pressure will drop by around 0.5 PSI for every 1000 feet you go above sea level, though this rate drops off the higher you go. With the correct algorithm, it’s easy to translate a pressure reading into an altitude estimate. If you want to try this yourself, the Pi Pico is one of the few Raspberry Pi products that is readily available and reasonably cheap. You can pick up a two-pack of the microcontrollers on Amazon for just over $12.