Solved

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

Posted on 2014-10-15
5
796 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 77

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AWS EC2 Linux 1 53
Linux server cannot access samba share 12 89
parse convert xml feed to text (python) 2 66
Using init script with Systemd: need help crafting unit file 11 76
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 …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now