Skip to content
This repository has been archived by the owner on Jun 14, 2023. It is now read-only.

Access to phone lat/lon #931

Open
chewiebrian opened this issue Aug 30, 2020 · 2 comments
Open

Access to phone lat/lon #931

chewiebrian opened this issue Aug 30, 2020 · 2 comments

Comments

@chewiebrian
Copy link

Hi, I am writing a watchface that consumes the yr.no API (https://www.yr.no/api/swagger/ui/index) instead your OpenWeatherMap weather data. The reason for that is because I want an hourly weather graph with at least three day info. Everything is working so far, even the 'internet companion' feature of AmazMod that lets me doing REST calls using the bluethooth data connection.

As the yr.no API needs the current latitude/longitude, I managed to retrieve it this way:

            final String weatherInfoJson = Settings.System.getString(service.getApplicationContext().getContentResolver(), "WeatherInfo");

            // Extract data from JSON
            JSONObject weather_data = new JSONObject(weatherInfoJson);
            if (weather_data.has("lat") && weather_data.has("lon")) {
                float lat = (float) weather_data.getDouble("lat");
                float lon = (float) weather_data.getDouble("lon");

                WeatherData.INSTANCE.setLat(lat);
                WeatherData.INSTANCE.setLon(lon);
            }

However, the latitude/longitude is truncated to 2 decimal positions, resulting in very poor positioning. Is there a way to retrieve more accurate coordinates from AmazMod?

@micrusa
Copy link
Collaborator

micrusa commented Aug 30, 2020

Try using it as a double instead of casting it to a float

@chewiebrian
Copy link
Author

The data is already truncated to two decimals in the JSON... Using float instead of double wouldn't affect.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants