Note: this is only adding a static location to geoclue. If you need more flexibility, there are google location API keys out there.
With the shutdown of Mozilla Location Service, many programs depending on geoclue break. (redshift, some browsers location, etc.) Some programs can be manually configured to a static location, but some can not. My preference is to keep them deferring to geoclue so there is only one static location to remember.
The new release of geoclue does support static address, but many distro releases will not be updated. Here we will point our old version geoclue at a local web server to tell it where we are. Internally geoclue uses libsoup which means it can’t open url file://, so we must feed it with http.
Reference
1. Install Nginx
$ sudo apt-get install nginx-light
2. Put the following in /etc/nginx/sites-available/static-location
server {
listen 127.0.0.1:8080;
server_name static-location;
root /var/www/html;
error_page 405 =200 $uri;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Note: thanks for the response code rewrite trick:
https://distinctplace.com/2017/04/17/405-not-allowed-nginx-fix-post-requests/
3. Link your new nginx rule to be enabled [you may want to remove any other links in this folder]
$ sudo ln -s /etc/nginx/sites-available/static-location /etc/nginx/sites-enabled/static-location
4. Set your static location by creating the following file at /var/www/html/static.json
{
"location": {
"lat": -22.7539192,
"lng": -43.4371081
},
"accuracy": 100.0
}
5. Make sure nginx is started [note: I have not verified if this starts at system start]
$ sudo service nginx status
$ sudo service nginx stop
$ sudo service nginx start
6. Edit /etc/geoclue/geoclue.conf to refer to the local server instead of Mozilla
url=http://localhost:8080/static.json
7. Verify geoclue is working
$ /usr/libexec/geoclue-2.0/demos/where-am-i
Client object: /org/freedesktop/GeoClue2/Client/1
New location:
Latitude: -22.753919°
Longitude: -43.437108°
Accuracy: 100.000000 meters
Timestamp: Tue 15 Oct 2024 22:57:16 (1728997036 seconds since the Epoch)