Read GPS location from command line via SSH I am wondering if there's a way to read the current GPS coordinates via SSH using SSHelper as SSH server.

I came accross some similar threads:


How to detect GPS status through adb shell?
A way to get location coordinates from command line
https://stackoverflow.com/questions/31707981/adb-shell-get-live-gps-location-not-last-known-location
Viewing the GPS-location of an Android Device?


I managed to run the SSH server and connect to it. So far, I have tried to run the dumpsys location command over ssh, which gives me the following:

Permission Denial: can't dump LocationManagerService from from pid=27381, uid=10192 due to missing android.permission.DUMP permission


Does that command only work with adb? If yes, is there another way of retrieving GPS coordinates over ssh, i.e. using some shell commands?

I don't have root, and I'm not an app developer. Thanks!
While I found no solution using SSHelper, it is indeed possible using Termux and the Termux-API. No root is required.

After installing the Termux app, one has to install the Termux-packages openssh and termux-api:

$ pkg install openssh
$ pkg install termux-api


I also had to install the Termux-API app from Playstore or F-Droid to get it working.

The sshd config can be edited as desired and can be found at $PREFIX/etc/ssh/sshd_config.

Set a password for SSH authentication (or, alternatively and even better, public key authentication with ssh-keygen and ssh-copy-id):

$ passwd


Next, start the ssh server:

$ sshd


To stop the server:

$ pkill sshd


In my case it's on port 8022 per default. One should now have access to the Termux-API commands via ssh. termux-location retrieves GPS data as JSON. For example: 

$ ssh u0_a202@192.168.0.7 -p 8022 termux-location
{
   "latitude": xx.xxxxxxxxxxxxxxxx,
   "longitude": yy.yyyyyyyyyyyyyyyy,
   "altitude": zzz.zzzzzzzzzzzz,
   "accuracy": 64.31999969482422,
   "vertical_accuracy": 192.0,
   "bearing": 301.9921875,
   "speed": 0.4399999976158142,
   "elapsedMs": 8,
   "provider": "gps"
}


Sources:

https://wiki.termux.com/wiki/Remote_Access

https://wiki.termux.com/wiki/Termux:API

https://wiki.termux.com/wiki/Termux-location