Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Other ways to specify location? #78

Closed
ab1jx opened this issue Dec 8, 2018 · 22 comments
Closed

Other ways to specify location? #78

ab1jx opened this issue Dec 8, 2018 · 22 comments

Comments

@ab1jx
Copy link

ab1jx commented Dec 8, 2018

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
Copy link
Owner

dglent commented Dec 8, 2018

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
Copy link
Author

ab1jx commented Dec 8, 2018

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
Copy link
Author

ab1jx commented Dec 9, 2018

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
Copy link
Owner

dglent commented Dec 9, 2018

Great i will add this feature to search by geographic coordinates

@ab1jx
Copy link
Author

ab1jx commented Dec 10, 2018

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
Copy link
Owner

dglent commented Dec 10, 2018

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
Copy link
Owner

dglent commented Dec 12, 2018

Could you test the commit below ?

Search city by geographic coordinates:
f05b6da

@ab1jx
Copy link
Author

ab1jx commented Dec 12, 2018 via email

@ab1jx
Copy link
Author

ab1jx commented Dec 12, 2018

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
Copy link
Author

ab1jx commented Dec 16, 2018

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.

@ab1jx ab1jx reopened this Dec 16, 2018
@dglent
Copy link
Owner

dglent commented Dec 16, 2018

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
Copy link
Owner

dglent commented Dec 16, 2018

The automatic geolocation doesn't work for you ?

@ab1jx
Copy link
Author

ab1jx commented Dec 16, 2018

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
Copy link
Owner

dglent commented Dec 17, 2018

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
Copy link
Author

ab1jx commented Dec 17, 2018

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
Copy link
Owner

dglent commented Dec 18, 2018

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
Copy link
Author

ab1jx commented Dec 18, 2018

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>

@ab1jx
Copy link
Author

ab1jx commented Dec 18, 2018

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
Copy link
Owner

dglent commented Dec 19, 2018

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

@dglent
Copy link
Owner

dglent commented Dec 19, 2018

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

@ab1jx
Copy link
Author

ab1jx commented Dec 19, 2018 via email

@dglent
Copy link
Owner

dglent commented Jun 9, 2019

After having added these 2 features:

  • Show the geolocation coordinates when searching a city
  • Detect automatically the geolocation by ip (from providers sites)

the basic need has been covered

@dglent dglent closed this as completed Jun 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants