Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

It seems like there is a package called geoclue which uses Mozilla's location service to lookup wireless access points and their known location, but there doesn't seem to be a command line interface for this. Is there another way to do it? Any clever hacks?

share|improve this question
    
Maybe this can help: askubuntu.com/questions/142581/… –  Parto Mar 6 at 9:28
    
Do you have a GPS device attached on on your USB ports? –  Radu Rădeanu Mar 6 at 15:09
    
@AvatarParto that answer only talks about the library there is no command line app for it. –  Mike McKay Mar 7 at 6:19
    
@RaduRădeanu I don't have a GPS device. I want to use the names of Wifi access points and a database of locations, like how OSX does it (and google also): support.apple.com/kb/ht5403 –  Mike McKay Mar 7 at 6:20
    
@MikeMcKay Yah, that's why I wrote 'Maybe this can help'. It's like more info or something. –  Parto Mar 7 at 6:26

4 Answers 4

If you want IP based lookup... (but you'll have to fix the HTML formatting of the output)

wget http://cqcounter.com/whois/my_ip_address.php && egrep "IP Location|City|Latitude|Longitude" my_ip_address.php
share|improve this answer

To get your location by IP you can use:

curl -s http://whatismycountry.com/ | sed -n 's|.*> *\(.*\)</h3>|\1|p'

To get your coordinates by IP you can use:

curl -s http://whatismycountry.com/ | sed -n 's/.*Coordinates \(.*\)<.*/\1/p'
share|improve this answer
1  
Any reason for -1? –  Radu Rădeanu Mar 7 at 14:05
1  
guess he is asking about Mozilla's location service to lookup wireless access points and their known location –  Rana Muhammad Waqas Mar 7 at 14:08

Here's my own best answer, which tries out all of the different geoclue providers available in Ubuntu:

apt-get install geoclue geoclue-ubuntu-geoip python-geoclue geoclue-yahoo geoclue-plazes geoclue-localnet geoclue-gypsy

echo "#!/usr/bin/env python

import Geoclue

providers = 'Gypsy, Hostip, Localnet, Plazes, Skyhook, Yahoo, Ubuntu GeoIP'
providers = providers.split(', ')
for provider in providers:

  POS_PROVIDER = provider

  location = Geoclue.DiscoverLocation()
  location.init()
  location.set_position_provider(POS_PROVIDER)
  position = location.get_location_info()

  print provider
  print position['latitude']
  print position['longitude']
" > location.py

python location.py

This results in:

Gypsy
0.0
0.0
Hostip
39.8121
-76.9837
Localnet
39.8121
-76.9837
org.freedesktop.DBus.GLib.UnmappedError.GeoclueErrorQuark.Code1: Could not understand reply from server
Plazes
39.8121
-76.9837
org.freedesktop.DBus.GLib.UnmappedError.GeoclueErrorQuark.Code1: Couldn't parse response from web service
Skyhook
39.8121
-76.9837
Yahoo
39.8121
-76.9837
Ubuntu GeoIP
40.6501
-73.9496

Which is a big step forward, but it seems that all of the providers are using IP based lookup, and my VPN totally throws that off. Seems like there should be a provider that only uses wifi access points, but I haven't found it yet.

share|improve this answer

There is a workaround that use your IP and find your location based to your Real IP.

first install lnyx

sudo apt-get install lynx-cur

Now the command is:

lynx -dump http://www.ip-adress.com/ip_tracer/?QRY=$1|grep address|egrep 'city|state|country'|awk '{print $3,$4,$5,$6,$7,$8}'|sed 's\ip address flag \\'|sed 's\My\\'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.