heikkilevanto / beertracker

Simple script to track the beers I drink
GNU General Public License v2.0
2 stars 1 forks source link

Gps #236

Closed heikkilevanto closed 1 year ago

heikkilevanto commented 1 year ago

Get gps coords for each location. Guess current location from gps

heikkilevanto commented 1 year ago

Getting the coordinates is just a simple javascript operation. Needs to be async, because the browser may ask the user to allow the coordinates to be used. Still, we can store current coordinates in the callback function.

The next problem is that we probably need to collect a few sets of coordinates for each location, to average out errors. That can best be done by storing the coordinates every time a beer is filed. We should actually call the coordinate-getting function on the save button, so as to get the latest coordinates - the page may have been up while I walk to another bar. If we have permission, we get better coordinates. If not, then not.

We should probably also disable the auto-filling of a default location in the form. If the user enters a location, we must trust that. If not, we can try to guess by coordinates, and if that fails, default to the latest location. We still need an algorithm to guess if are at a known beer location, or somewhere unknown.

When editing a beer entry, we should of course keep the location data as it is, or allow the user to edit/remove it. Editing of records may well happen on a different location, like after coming home.

One last problem is the format of the data file. We can add coordinates to the location field, as in "Ølbaren [lat/long]", and filter the [] away before displaying or filtering. When reading the file, we can collect all the coordinate pairs for each location, and average them out before comparing the current location. This still risks some dirty data getting us wrong guesses, but those can be edited manually until we have sufficient data.

heikkilevanto commented 1 year ago

Damn thing will not work on FF, never gets the callback. On Chrome it works as it should. Took some time before I got around to testing on Chrome. May need a bit more googling for FF. Could be something about the geoclue package?

Next I need to add the coordinates to the input form, save them in the location field, and filter them out when reading the file. That looks doable. Some corner cases like record editing.

heikkilevanto commented 1 year ago

Separated the location guessing into its own issue, #238

heikkilevanto commented 1 year ago

Tried to make the "location [lat/long]" trick, but there are too many places. Need to make the geoloc a real field in the data file format, and adjust where ever affected. And convert my data file(s). Since I am the only user, that can be done in one messy go.

heikkilevanto commented 1 year ago

See also #208

heikkilevanto commented 1 year ago

Ok, have the data file. Was surprisingly easy, once I realized that I have to add the field at the end of the line

heikkilevanto commented 1 year ago

Starnge. I removed the geoclue package, and now FF can get my location. My guess is that the geoclue got stuck trying to locate a wifi point, but my desktop machine doesn't do wifi. Maybe FF has a better fallback for that case, probably looking up via my IP address. Not sure where that points, but at least I get something that looks stable.

heikkilevanto commented 1 year ago

Added a hidden geo input to the beer board, and the copy buttons, and modified the geo routine to set the geo value to all inputs named 'g'

heikkilevanto commented 1 year ago

Seems to work, for now.