vadret / android

đŸŒ¦ Vädret
https://vadret.github.io/android/
Other
17 stars 3 forks source link

feature: Inculude cities outside Sweden #197

Closed Bjoessi closed 4 years ago

Bjoessi commented 4 years ago

The SMHI service includes weather info also outside Sweden. Adding this would be useful when traveling between e.g. Nordic countries.

sphrak commented 4 years ago

@Bjoessi this is already a feature if you are using the GPS position as long as you are inside of the supported geographical area, are you saying this does not work for you? If you travel outside of the supported area an error will be displayed.

This does however not work if you search for a city manually, since that list is derived from a public list of swedish cities which is hosted on your device. There is simply no easy way to generate such a list of cities that happen to be within the supported geographical area that SMHI supports, thus I cannot support it. Unless you happen to know a way.

Bjoessi commented 4 years ago

Aha. I switched on the GPS and I get some kind of weather forecast (but the forecast doesnt match what is displayed on SMHI.se. I am currently in Uusima, Finland, where can I see what is considered "supported area"?

sphrak commented 4 years ago

@Bjoessi

According to the SMHI documentation it should be roughly this area.

Uusimaa looks like a quite large region of Finland? The app will send your latitude and longitude when you open the app and SMHI then returns whatever the weather is on that position your device reported. I believe the forecast resolution is a couple of kilometers per sector so it will vary depending on where you are.

Bjoessi commented 4 years ago

@sphrak It seems there are two separate issues here. First, SMHI and Vädret seems to be interpreting the position name differently, Vädret seems to be using the city name and SMHI seems to be using more specific locations within a city. I suppose this is not a bug but rather but a design choice.

Secondly, I also get the feeling that something is peculiar about the time. Could it be that the app has problem with daylight saving or that I am currently one hour ahead from Sweden? I added also a screenshot of the Finnish weather app as reference.

Screenshot_20200518-150302 Screenshot_20200518-150325 Screenshot_20200518-151748

sphrak commented 4 years ago

@Bjoessi sorry for taking long time to reply. But yes you are right in that its two different issues.

Supporting other cities outside sweden

What ends up happening on a device that uses gps to lookup the weather report is that it sends an "as accurate" position it can retrieve from the android system and sends it to SMHI's API and then the app just renders whatever weather data the API returns.

The location "name" in the upper right of the app, is figured out by doing a "reverse nominatim" lookup, by sending latitude/longitude to openstreetmaps api and just pick the first good fit returned by them. The quality or accuracy of these names vary a lot since OSM is created mainly by user contributions and sometimes contains inaccuracies.

In the end its currently not possible to support more cities other than Swedish ones, at least not by text because its a text file I maintain manually -- whatever works outside of sweden via GPS will work as it works currently, there is little I can do about it. However in the future I might switch out SMHI API in favor of YR.NO API instead since they do support around ~16000 locations in the entire world, the downside is they do not support lookup via gps so I am not entirely sure if I am a fan of that.

The issue about the times

I was recently contacted regarding this issue, and upon further investigation it turned out that time was not correctly parsed. The times from SMHI are returned in UTC format which then is converted to localtime (whatever timezone your device uses). Turned out this was done incorrectly, but has since been fixed here: https://github.com/vadret/android/pull/230