You are not logged in.

#1 2013-07-19 16:54:36

enduser
Member
Registered: 2012-10-04
Posts: 25

Get GPS location from the command line

Is there a utility to get the current GPS location from the command line?  A quick search says `geo` will do it, but that appears to come with the android dev tools, which I'd rather not install right now.  The reason I want to do this is to avoid hard-coding my coordinates in a call to `redshift`.

Offline

#2 2013-07-19 20:17:49

Nisstyre56
Member
From: Canada
Registered: 2010-03-25
Posts: 85

Re: Get GPS location from the command line

Wouldn't that necessarily require a GPS device?


In Zen they say: If something is boring after two minutes, try it for four. If still boring, try it for eight, sixteen, thirty-two, and so on. Eventually one discovers that it's not boring at all but very interesting.
~ John Cage

Offline

#3 2013-07-19 20:37:41

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Get GPS location from the command line

Approximating location can also be done with the IP address.  The relevant packages in the repos is geoip and geoip-database.  But I think that it is limited to simply determining what country your are in.  In the US, that doesn't really tell you too much in terms of positioning.

Offline

#4 2013-07-20 00:32:07

Nisstyre56
Member
From: Canada
Registered: 2010-03-25
Posts: 85

Re: Get GPS location from the command line

WonderWoofy wrote:

Approximating location can also be done with the IP address.

I'm aware of that but the OP was asking for a GPS tool.


In Zen they say: If something is boring after two minutes, try it for four. If still boring, try it for eight, sixteen, thirty-two, and so on. Eventually one discovers that it's not boring at all but very interesting.
~ John Cage

Offline

#5 2013-07-20 00:44:09

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Get GPS location from the command line

Nisstyre56 wrote:
WonderWoofy wrote:

Approximating location can also be done with the IP address.

I'm aware of that but the OP was asking for a GPS tool.

Yeah, this is true.  But there was also the reference to redshift as being the reason for trying to find such a tool, and that is what I was really trying to address.  Sorry about the confusion, as I should prbably have specified that in my post.  Also, I realized that it is not geoip that redshift works with, but geoclue.

Offline

#6 2013-07-20 00:47:31

progandy
Member
Registered: 2012-05-17
Posts: 5,269

Re: Get GPS location from the command line

The most common tool on linux is gpsd. It can talk to many different devices and present the data in a unified format. To get the raw data in a terminal, run gpspipe.


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#7 2014-03-07 18:22:21

enduser
Member
Registered: 2012-10-04
Posts: 25

Re: Get GPS location from the command line

Thanks! I'll look into it.

Offline

#8 2014-03-07 19:38:46

nomorewindows
Member
Registered: 2010-04-03
Posts: 3,408

Re: Get GPS location from the command line

Bash script found across the internet:

#!/bin/bash
date
#gpsdata=$( gpspipe -w -n 10 |   grep -m 1 lon )
gpsdata=$( gpspipe -w | grep -m 1 TPV )
lat=$( echo "$gpsdata"  | jsawk 'return this.lat' )
lon=$( echo "$gpsdata"  | jsawk 'return this.lon' )
alt=$( echo "$gpsdata"  | jsawk 'return this.alt' )
dt=$( echo "$gpsdata" | jsawk 'return this.time' )
echo "$dt"
echo "You are here: $lat, $lon at $alt"

Just modify it so that redshift -l $lat:$lon ...
Having a devil of a time trying to get that to work in awesomewm.


I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.

Offline

#9 2014-05-07 00:49:13

enduser
Member
Registered: 2012-10-04
Posts: 25

Re: Get GPS location from the command line

Hmm.. `gpspipe` gives me:

gpspipe: could not connect to gpsd localhost:2947, Unknown error -6(-6)

And `gpsd` gives me:

gpsd:ERROR: can't run with neither control socket nor devices

Do I need to be root for these applications? Alternatively, could I maybe just grab the timezone from /etc/localtime and use that? (though I guess that doesn't get close enough on longitude...)

Offline

#10 2014-05-07 00:55:40

nomorewindows
Member
Registered: 2010-04-03
Posts: 3,408

Re: Get GPS location from the command line

enduser wrote:

Hmm.. `gpspipe` gives me:

gpspipe: could not connect to gpsd localhost:2947, Unknown error -6(-6)

And `gpsd` gives me:

gpsd:ERROR: can't run with neither control socket nor devices

Do I need to be root for these applications? Alternatively, could I maybe just grab the timezone from /etc/localtime and use that? (though I guess that doesn't get close enough on longitude...)

You have to start gpsd from systemctl.  And you can plug/unplug gps devices at will, so it can be enabled in systemctl whether or not an actual gps is always available.


I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.

Offline

Board footer

Powered by FluxBB