Solved

Bash script to get GEO location from http://freegeoip.net/

Posted on 2014-10-15
5
838 Views
Last Modified: 2014-10-19
Could someone share some Linux bash code which uses the http://freegeoip.net/ service to get lat/lon into two variables.

I basically just need to add this functionality to a bash script I have, picking up the lat/lon of the location I am running the script from.

As I understand it, http://freegeoip.net/ is 100% free to use regardless of use.
0
Comment
Question by:projects
5 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 40383345
LATLON=$(wget -o /dev/null -O - http://freegeoip.net/xml | awk -F'<|>' '/Latitude|Longitude/ {print $3}')

LAT=$(cut -f1 -d" " <<< $LATLON)
LON=$(cut -f2 -d" " <<< $LATLON)

echo "Latitude: " $LAT
echo "Longitude:" $LON
0
 

Author Comment

by:projects
ID: 40383482
Seems to work fine.

Any chance you could tell me what type of field and size I might use in MySQL to store these and other potential results?

Latitude:  xx.7685
Longitude: -xx2.8815

It sounds like using MySQL Spatial Extensions is the way to go but I've not found any examples of what to set the new fields to.

Currently, I have;

       geo_lat       decimal(10,8)       No       None       NULL       
      geo_lon       decimal(11,8)       No       None       NULL

And the data being stored looks like;

      34.76850000       -112.88150000
0
 
LVL 78

Expert Comment

by:arnold
ID: 40383673
What are you looking for? converting the data and rendering it as  34° 46' 6.6" N 112° 52' 53.4" W?

some avoid the float/decimal by multiplying the data by 10^8 and storing the data as int (10) when when needed, divide by 10^8
i.e your stored data will be 3476850000 -11288150000
Some only go to the six digit precision or fewer, depending on how "precise".
0
 

Expert Comment

by:erix molinie
ID: 40389740
Hi,
it's an interesting problem or case and the answers gave to you are good.
but, as it has been already asked you, what are you trying to do.
"freegeoip" is certainly a good website but it's not accurate and it relies on informations provided by Internet/Phone companies I suppose. For example, if I take my @IP, the localization is 100km far from where I am..
The country is good, the region is good but not the city/town/village.
Regards
Erix
0
 

Author Comment

by:projects
ID: 40390360
What I am trying to do is simply to get the lon/lat geo location of something using a script.
I need to use a 100% free GEO location service which doesn't impose limits in any manner including for commercial use.

I only need to use it once to set the device unless it's position changes which would be very rare. My usage would be very low.

I already awarded the solution because I was looking for a little code to do this.


Another that I really like is
http://www.datasciencetoolkit.org/developerdocs#ip2coordinates

I like this one because I already have the address information in the database and it looks like if I sent this one the IP and some of the address info, it would be more accurate?

I am going to post a new question. Thanks.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Zimbra on Amazon Linux help 7 112
AWS EC2 HTTP & HTTPS 2 76
Samba Question 11 107
Advice on ESXi 5.1 Health / Storage 1 45
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question