views:

184

answers:

4

I am looking for a good geolocation api to use from bash. I want this call to return at the very minimum the name of the city I am in, and the state.

I imagine that there must be some site I can curl, or some scripting language that has a package that works. The machine does not have a GPS, but it does use wireless internet most of the time if that is needed.

A: 

Wireless internet meaning WiFi, CDMA2k, UMTS, EDGE... ? And your carrier? Not that it matters.

Really. I'd start investing in a GPS dongle.

vladr
just good ol 802.11g. I shouldn't need a gps if my browser can get my location without one.
icco
I assume this is for yourself -- a mobile computer? :) You can get *a* location without GPS, never guaranteed to be the right one (GeoIP services can place you in a completely different state just because the ISP is registered there in `whois`.)
vladr
+2  A: 

Scraping the first Google hit result for "geoip" seems to work easily enough.

$ curl http://www.maxmind.com/app/locate_my_ip |
> awk '/<table>/{RS=RS RS}/tblProduct1/'

I haven't checked their EULA to see if using their service this way is okay, but they do also provide GeoIP libraries for C, Perl, Python, etc. with a "lite" database that you can distribute (with conditions).

ephemient
Well, I'm in Cambridge MA yet maxmind puts me in Boston (close, but not the same), and hostip.info puts me in... Reston, VA, etc. :) Not surprising since probably more than half the info still comes from `whois`.
vladr
Cool. I'm trying to think now of a good way to grep out just the city, region and country.
icco
+1  A: 

I was looking at this problem again recently and found whereami, a geolocation bash script for Mac OS X Snow Leopard, which takes advantage of Core Location. This will tend to be much more precise than IP geolocation, and it works well in my tests.

npdoty
That is just sexy. Thanks for the link!
icco
+1  A: 

geolocate-cli is still in alpha but should do the job.

fmark