dglent / meteo-qt

System tray application for weather status information
GNU General Public License v3.0
83 stars 21 forks source link

Other ways to specify location? #78

Closed ab1jx closed 5 years ago

ab1jx commented 5 years ago

Openweathermaps lets you specify a location by city, zip/postal code or lat & long. City,country is particularly inadequate in the US, I see 3 cities in the US with my city name.

dglent commented 5 years ago

Hello

Maybe the zip code could help more for this case as the coordinates needs to click and go to the map to check.

ab1jx commented 5 years ago

https://developers.google.com/maps/documentation/geolocation/intro#responses

Using geolocation might work, if you can jump to the nearest weather station from that (lat & long). Not sure about zips, maybe there's a lookup table somewhere that crosses them to lat & long. I normally get a full weather forecast from NWS at http://forecast.weather.gov/MapClick.php?lat=42.65050&lon=-72.8298&unit=0&lg=english&FcstType=text&TextType=1

That is my exact GPS lat & long, I let NWS match it to a forecast.

What are the numbers? My station is (maybe) 4830099 or 4950747 or 5157262. That's not the Yahoo woeid is it? My woeid is 12758427

ab1jx commented 5 years ago

OK, user inputs a lat & long or it comes from geolocation (hopefully not geoip: terrible). Some server has all the known weather stations in some big table. 2 binary searches among lat & long data and you've got the 4 nearest weather stations. Present those to the user or use the geometrical distance formula to pick the closest one. It won't need to be done often.

dglent commented 5 years ago

Great i will add this feature to search by geographic coordinates

ab1jx commented 5 years ago

Good geolocation test page (look at the page source). https://benwerd.com/lab/geo.php The API is mostly used by phones with internal GPSes, but at least with Firefox it's possible to set up a file on fixed computers with no GPS that emulates it. And just a pair of edit boxes to input lat & long manually would be useful for when all that's not working or isn't set up.

Good app, I'm recommending it on a Raspberry Pi page at https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=227884&p=1397877#p1397877

dglent commented 5 years ago

The above page is very usefull in order to get the geolocation, i will check it . The above commit shows the coordinates in the results.

dglent commented 5 years ago

Could you test the commit below ?

Search city by geographic coordinates: https://github.com/dglent/meteo-qt/commit/f05b6da417adec1fc874a7e311486e24a7bb28af

ab1jx commented 5 years ago

It sort of works but the cities are wrong. That may happen somewhere else.

I was able to get the match as I type to work for coordinates a little, but I knew from yesterday that I wanted station code 4950747. Now that code shows as Shelburne. And when I type the coords into Google Maps it shows up as Shelburne. Could they have reassigned the number overnight?

The screenshot from the phone shows the weather station I want at the red marker. I recognize it, it's at the local postoffice. That's from typing the coords into Google Maps to see where they actually point to. My actual location is at the top of the dark blue area at the bottom of matching.png. {"location":{"lat":42.650515,"lng":-72.829819},"accuracy":5}

On 12/12/18, Dimitrios Glentadakis notifications@github.com wrote:

Could you test the commit below ?

Search city by geographic coordinates: https://github.com/dglent/meteo-qt/commit/f05b6da417adec1fc874a7e311486e24a7bb28af

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/dglent/meteo-qt/issues/78#issuecomment-446493647

--

No, I won't call it "climate change", do you have a "reality problem"? - AB1JX Cities are cages built to contain excess people and keep them from cluttering up nature. Impeach Impeach Impeach Impeach Impeach Impeach Impeach Impeach

ab1jx commented 5 years ago

I replied to the email because I attached some images. OK, it's picking it up here too. Except not the images.

See the end of https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=227884&p=1403190#p1403190 where the images are working. Matching while typing coordinates is maybe a bad idea.

I thought close referred to the dialog box not the issue. It's workable.

ab1jx commented 5 years ago

That doesn't quite work either. Doing any ASCII search probably won't. Latitude and longitude are originally expressed in degrees, minute and seconds. Computers (mostly) use a decimal number like 42.650515. Each degree is broken into 60 minutes, each of those is 60 seconds. So the decimal is latitude + (minutes/60) + (seconds/3600) (roughly). If you express the coordinates as 2 doubles that's probably close enough, but they need to be numbers, not ASCII. The best discussion I could find quickly is at https://www.wikihow.com/Read-Latitude-and-Longitude-on-a-Map Decimal lat and long: https://www.wikihow.com/Write-Latitude-and-Longitude

Trying to use your geolocation interface landed me in New York because it's trying to match latitude first and assumes longitude is less significant. It's 2-dimensional, you can't do that.

dglent commented 5 years ago

All tests i do work here. Could you give me an example ? In the example of the above link, you search for 38.53,-77

I don't understand for the "ascii" part of the question: You add the coordinates and then it is created an url to request the place to openweathermap.com: http://api.openweathermap.org/data/2.5/find?lat=38.53&lon=-77.0&type=like&mode=xml&APPID=xxxxxxxxxxx You cannot specify anything else Example of city name search results with coordinates: https://openweathermap.org/find?q=london And the API of the url with coordinates request: https://openweathermap.org/current#geo

dglent commented 5 years ago

The automatic geolocation doesn't work for you ?

ab1jx commented 5 years ago

The "Find my location" icon doesn't work, it says N/A in the top window, "No results" at the bottom. Yet this geolocation test page works https://benwerd.com/lab/geo.php

By ASCII I mean letters, words as opposed to numbers. Coordinates are 2 numbers. Trying to "match as typed" can at best match the first one. And my coordinates don't exactly match any weather station's so trying to match characters won't work. You need to treat them as numbers and find the closest ones. It's like X and Y in Cartesian coordinates in math. Matching as text lands me in New York because I'm north of New York by 300 km and it only looks at the first number.

Pictures would be easier, but clicking the left icon in that dialog, the one with the magnifying glass and entering my coords as 42.65,-72.83 gets me the list 4932757 - Charlemont - - 42.6279 - -72.8699 4931627 - Buckland 42.5923 --72.7918 etc.

Those are close but what I use is: Heath_US- lat: N S 42.6734°- lon: E W -72.8218°_4950747 (same #, hmm)

Hmm, I made a little HTML file with the http://api.openweathermap.org/data/2.5/find?lat=38.53&lon=-77.0&type=like&mode=xml&APPID=xxxxxxxxxxx URL copied from above and put in my coords and API key. When I click the link in my browser it brings up weather data from 5 cities all on one page: Charlemont, Buckland, Shelburne Falls, Colrain, Shelburne. So if you're using OWM's matching that part works I guess.

The geolocation button doesn't work, maybe because it's looking for an exact match and there isn't one. Those 5 cities are all within 15 km or so. But if I type the "lat: N S 42.6734°- lon: E W -72.8218°" coords from above into Google Maps it's under 3 km away and there is a weather station there because that's the one that WeatherBug uses. Town hall, town weather station.

Maybe some confusion comes from the fact that I live in a village of 800 people, not a city. OWM may be lumping them all together. But there's a big difference in altitude, I'm 487 meters above sea level, so the weather's different up here.

In what I get back in my browser I see that 4950747 is a "city id" by OWM: Shelburne at coord lon="-72.6885" lat="42.5898". So they're grouping Heath into the same city id even though it's 17 km away. That's a problem with Open Weather Maps, not with your program.

http://api.openweathermap.org/data/2.5/find?lat=42.650515&lon=-72.829819&type=like&mode=xml&APPID=296b517eddb0adaeb7226b3048de5b60

dglent commented 5 years ago

Ok i see For the coordinates, the resolution is done in OWM side. The only thing meteo-qt does is to send an url with the entered latitude and longitude. So it seems that they don't provide your city when searching by coordinates

For the automatic geolocation i didn't use your site because it needs a click from the web browser (accept geolocation). Probably programmatically i need to make a webbrowser call and simulate the click to accept the geolocation. I found this site http://ipinfo.io/json which provides the geolocation without click. If you open this site in the web browser, it works ?

ab1jx commented 5 years ago

Well I shouldn't need a city, weather came before cities. I like my NWS URL of https://forecast.weather.gov/MapClick.php?lat=42.65050&lon=-72.8298&unit=0&lg=english&FcstType=text&TextType=1 You can edit your (US) coordinates into it and save it, email it, put it in your bookmarks toolbar, etc.

Accept geolocation is part of HTML 5 I think. Without that phones could send their locations without the owner's permission, making it possible (easier) to track them. Mine is just the first site I found a few years ago that worked for testing my local json file and Firefox setup so I kept using it. Yours, twice now says "Rate limit exceeded. Upgrade to increase your usage limits at https://ipinfo.io/pricing, or contact us via https://ipinfo.io/contact". Do you need an API key or something? Cookie? Oh well.

You don't have a Bitcoin ticker that sits in the tray up your sleeve by any chance? :)

ipinfo.io seems to be owned by Google. I was curious to see where it was that such a thing would work. nslookup on ipinfo.io comes back to 216.239.32.21 (and 3 others), then whois on 216.239.32.21 comes back to Google LLC.

dglent commented 5 years ago

Ok so it is not a good solution this site. I thought that they allow a minimum number of lookups for free. I tested multiple times though without any problem. It may have region or other restrictions (?) I will try to find another solution

Sorry nothing for bitcoin here :(

ab1jx commented 5 years ago

It's Google, they're trying to make money off it. There's nothing in the URL to identify a user, maybe they only want to charge people with US IP addresses. Maybe it's because I use ad-blockers so their advertising doesn't load.

Anyway it's not rocket science but it does need to run on some server. I wrote this 11 months ago. If I open it as file:/// it doesn't work, but I'm running Apache (and nginx) on this Raspberry Pi. If I open it as http://127.0.0.1/geodemo.html it works. You could put something like it on any server, customize it however you want. It's only a first-time thing anyway, you don't need it often. Hmm, you're using Qt right, do you have a /usr/include/QtLocation directory? I'm not sure what mine came with, I do have QtCreator on here. I've only played with it a couple times. On Linux I wouldn't be sure there isn't something in /proc but only Firefox is looking at my json file, I don't have a real GPS on this. Anyway the HTML, which will probably get mangled by this form. I could email it as an attachment.

It tells me: Latitude is 42.650515° Longitude is -72.829819°

<!doctype html>


the work is done by: navigator.geolocation.getCurrentPosition(success, error); and then: var latitude = position.coords.latitude; var longitude = position.coords.longitude;

This page seems to filter everything useful out but see https://www.mozilla.org/en-US/firefox/geolocation/ and https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation

ab1jx commented 5 years ago

https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation and https://www.mozilla.org/en-US/firefox/geolocation/

It works by doing navigator.geolocation.getCurrentPosition(success, error); then you can get to position.coords.latitude and position.coords.longitude

In Javascript, I don't know about Qt. In the above I don't see anything past the doctype line, that's the first of 53 lines.

In Qt look at QGeoLocation QPlace::location() const and GPSLatitude. Qt seems to treat GPS stuff like media stuff. How you fake it if you don't have a GPS connected I don't know. A couple of edit/text boxes or an ini/rc file would work.

http://doc.qt.io/qt-5/qtpositioning-index.html

dglent commented 5 years ago

Thanks for the hints I will try to find out the best method to improve the geolocation accuracy Try please the above commit

dglent commented 5 years ago

It seems that this site has also a good detection: https://iplocation.com/

ab1jx commented 5 years ago

On 12/19/18, Dimitrios Glentadakis notifications@github.com wrote:

It seems that this site has also a good detection: https://iplocation.com/

No, I just tried it and it put me in New York City, it's looking at the network connection, not GPS.

Your IP address | 107.242.117.7 40.67 -73.9367 United States New York Brooklyn AT&T Wireless

Because I connect through a cell phone my IP address is usually irrelevant nonsense Brooklyn is 300 km away, 3 1/2 hour drive by car.

Qt seems to be able to read the computer's lat & long without using any browser. Or maybe that's just for EXIF data contained in images.

I just discovered the lat & long end up in ~/.config/meteo-qt/meteo-qt.conf but actually the weather station ID is the most important thing since that's what governs which data gets fetched. The ID= line.

My project BTW: https://sourceforge.net/p/fdf/ (off topic)

-- You are receiving this because you modified the open/close state. Reply to this email directly or view it on GitHub: https://github.com/dglent/meteo-qt/issues/78#issuecomment-448692568

dglent commented 5 years ago

After having added these 2 features:

the basic need has been covered